Tải bản đầy đủ - 0 (trang)
Chapter 3. Defining and Working with Fields

Chapter 3. Defining and Working with Fields

Tải bản đầy đủ - 0trang

WorkingUndertheHood

Fieldsaretheheartofanydatabase.Bystoringinformationin

properlycategorizedfields,youimpartbothfunctionand

meaningtowhatwouldotherwisebeanincomprehensiblepile

ofrawdata.

We'llspendmuchofthischapterdescribingwhatkindsoffields

existinFileMakerPro,howtheystoreinformation,andhowto

ensureproperdataintegrityinyourdatabasesolutions.

Ifyou'renewtodevelopmentinFileMakerPro,thischapterisa

goodplacetostart.Nodoubtsomeofthetopicswecoverwill

lackacertaincontext,butestablishingasolidfoundationin

fielddefinitionisavitalpartofbecomingapracticeddeveloper.

IfyouhavebuiltafewFileMakerProdatabases,youmayneed

onlytoskimthischapter.Ofthetopicswecoverhere,indexing

islikelythemostadvanced;ourdiscussionexploressome

subtledifferencesfrompriorversionsofFileMakerPro.



NewDatabasesBeginwithFieldDefinitions

Tocreateanewdatabase,simplylaunchFileMakerProandthen

chooseFile,NewDatabase.You'llbepresentedwiththeoption

tostartwithatemplateortocreateanew,emptyfile.Tocreate

afileofyourown,selecttheCreateaNewEmptyFileoption

andclickOK.

Afteryou'vesteppedthroughthesefirsttasks,you'llbetaken

totheDefineFieldsdialog.



WorkingwithTemplates

Werecommendthatyougobackatsomepointandworkwiththetemplatesthat

shipwithFileMaker.They'reagoodlearningtool,andyouwillbeabletoseehow

fieldsaredefinedinthesefinishedsolutions.Therearedozensoftemplates,

they'renotallthatcomplicated,andthey'llgiveyousomegoodideasfor

designingyourownsolutions.Fromthemyoucanlearnaboutsimpleuser

interfacesandcalculationfunctionsandcanseesomebasicscriptsinactionas

well.



UsingtheDefineDatabaseDialog

Whenyouchoosetostartonanew,emptydatabase,FileMaker

ProcreatesafileforyouandautomaticallyopenstheDefine

Databasedialog(showninFigure3.1).Asadeveloper,you'll

spendagoodbitoftimeinthethreetabsinthisdialog.

FileMakerPro'sDefineDatabasedialogallowsyoutocreatethe

fields,tables,andrelationshipsyouneedinordertoformyour

database.Italsoenablesyoutomodifyawiderangeof

attributesassociatedwithfields,suchasauto-entryfunctions,

validation,storage,andcalculationformulas.Itisthese

elementsthatcomposeadatabase'sstructureorschema.Itis

herethatyouformyourdatabasebehindthescenes.



Figure3.1.Thethreetabsallowyoutoswitch

amongdefiningtables,fields,andrelationships.



Note

NoticetheactivetableinFigure3.1.Thefieldsyou

defineareassociatedwiththisselectedtable.



FileMakerProwillhavealreadycreatedadefaulttableforyou,

namedthesameasthefileitself.NoticetheTablemenu

selectionontheFieldstabofthedialoginFigure3.1.Anyfields

youcreatewillbecreatedinthattable.

Forsomebasicinformationontables,see"UnderstandingTables,"p.

31.



Foradetaileddiscussionofmultiple-tablesolutions,seeChapter6,

"WorkingwithMultipleTables,"p.157.



NoticethethirdtabintheDefineDatabasedialog:

Relationships.Wewon'tbecoveringmultitablerelational

databasesinthischapter,butitisonthattabthatyou'dcreate

therelationalassociationsamongtablesinyoursolution.

Forinformationonrelationaldatamodeling,seeChapter5,"Relational

DatabaseDesign,"p.129.



Tip

Commentingisavitaldisciplinetodevelop.

Spendingafewmomentstoaddinformationtothe

Commenttextbox,belowthefieldname,asyou

createsomethingwillsavetimelaterintryingto

figureoutwhatyouwerethinkingatthetime.

Toviewcomments,togglebetweenoptionsand

commentsatthetopofyourfieldlist.







WorkingwithFields

EverytableinanydatabaseFileMakerProorotherwiseisa

collectionofinformationstoredinfields(orcolumns,ifyou're

familiarwiththatterminology).Itisbystoringinformationin

appropriatefieldsthatadatabaseisgivenmeaning.

Forexample,byentering"124MainStreet"inafieldcalled

Address,we'veidentifiedwhat"124MainStreet"is.Inthecase

ofastreetaddress,it'sfairlyeasytoidentifywithoutafield

definition,butwhatabout"912.5"allonitsown?Thatcouldbe

aprice,anumberofunits,achapterheading,orathousand

otherthings.Whenyouplacethatnumberintoanamedcolumn

orfield,yourdatabecomesmeaningful.If"912.5"satinafield

namedTemperature,you'dlikelyconcludethatitisprettydarn

hot.Conversely,ifitsatinaKilobytesAvailablefield,you'dlook

tobebuyinganewharddrive.Keepthisultimategoalof

impartingmeaninginmindasyoucreateandnamefields,and

assignappropriatedatatypestothem.



FieldNamingConventions

OneofthenicethingsaboutFileMakerProdevelopmentisthe

freedomdevelopershaveinnamingfields.(FileMakerProisnot

uniqueinallowingdevelopersfieldnamingfreedom,bythe

way.)Thatfreedomalso,unfortunately,givesrisetoconfusion

andarbitrarynamingconventions.Name_xTJm2maymean

somethingtosomeone,orNamemightalso,butboth

examplestheoverlyspecificandtheoverlygeneralrequirea

strongfamiliaritywithagivensystem.Ifyoueverreturntoa

databasemonthsafterbuildingit,oddsareyouwillhave

forgottenyourcleverabbreviations.

ForacompletepresentationofSoliantConsulting'scodingstandards,



seeChapter27,"DocumentingYourFileMakerSolutions,"p.841.



WeencourageyoutotakeadvantageofFileMaker'sallowance

forlongfieldnamesofupto100characters.Usefulltext

names(likeStreetAddressline1),avoidabbreviations(orifyou

usethem,besuretoprovideanobviouskey!),andtrytogroup

thingslogically.NotethatalthoughFileMakerallowsforspaces

andspecialcharacters,werecommendusingunderscores,

letters,andnumeralsonly.

Here'sanexampleofwhatwe'dconsiderafairlyreasonable

approachtonamingfields:

Address_City

Address_Postal_Code

Address_State

Address_Street_line1

Address_Street_line2

Person_Name_First

Person_Name_Last

Phone_Home

Phone_Work

Thesefieldsarequitesimpletoidentifyandareneatlygrouped

togetherwhensortedalphabetically.Thisisn'tsuchabigdeal



forsmalldatabases,butifyoueverworkonalargedatabase,

withmultipledevelopers,awell-establishednamingconvention

isvital.Weencourageyoutoadoptgoodprogramminghabits

rightfromdayone.

Anothercommonapproachmanydevelopersuseincludes

abbreviationsfordatatypes.Oftenit'shandytoknowthedata

typeofagivenfieldwhenworkingwithitwithouthavingto

refertotheDefineDatabasedialog.Herewe'veused"t"for

text,"n"fornumber,and"c"forcalculation:

ProductName_t

Price_n

TaxRate_n

Tax_c

We'llcoverindexinglaterinthechapter,butsomedevelopers

alsonotewhetherafieldisindexed("x"forindexed,"n"for

unindexed):

Location_Name_tx

Location_Desc_tn

Location_Size_nn

Somenamingconventionsalsobreakoutadivisionbetween

datafieldsandwhatarecommonlyreferredtoasdeveloper

fieldsthosefieldsthatyouneedonlytomakeyourFileMakerPro

solutionwork.Ifyoueverwenttoimportyourdatabase

wholesaleintoanothersystem,thesefieldswouldprobablybe

leftbehind.Herewehavetwoabbreviations:"k"forkey(or



matchfield),and"z"(sothatitsortstothebottomofthelist)

fordeveloperutilityfields.Wealsouseunderscorestoensure

thatkeyssorttothetopofourfieldlist,withtheprimarykey

comingfirst.

Tounderstandhowkeysareusedtoidentifyrecordsintablesandform

relationships,seeChapter5,"RelationalDatabaseDesign,"p.129.



__kp_primary_AlbumID

_kf_foreign_ArtistID

AlbumName

Date

z_SelectedPortalRow

z_UserColor_Preference

z_UserGenre_Preference

Finally,here'sarealexamplefromadatabasewerecentlywere

hiredtomodify(usedwithpermissionandgoodhumor!):

BikeType

WheelDm

BikeName

Model



Type

Temp

Date

Bike

Bike2

Sp.99Meas

TireDm

Bikeid

Sku

2002TireDiam

1999TireDiam

BikeMODEL

SUMMARY

zTempzzz

Philsfield(nolie!)

We'resurethatwe'vebelaboredthepoint,butthisdatabase

wasdifficulttomodifynotbecauseitwascomplex,butbecause

itwashardtointerpret.Asinallthings,alittleplanninggoesa

longway.



Ifyou'replanningonusingFileMakerProasawebbackend,referto

"ProblematicFieldNames"inthe"Troubleshooting"sectionattheendof

thischapter.



FormoreinformationonusingdatabasesontheWeb,see"Designing

forIWPDeployment,"p.648,aswellasChapter23,"CustomWeb

Publishing,"p.699.



Formorethoughtsondocumentingandcommentinginyourdatabase,

seeChapter27,"DocumentingYourFileMakerSolutions,"p.841.



TherearesomerestrictionsonfieldnaminginFileMakerPro:A

fieldnamemustbeuniquewithinitstable,andmustbeless

than100charactersinlength.

Youcanopttousespecialcharacters,numbers,spaces,even

thenamesoffunctions,butwerecommendagainstusingthem.

Ifyouuse,(comma),+,-,*,/,^,&,=, ,>,<,(,),",;

(semicolon),:(colon),or::(doublecolonrelationship

indicator),youneedtoenclosesuchspecialcharacterswithina

$()incalculationformulastohavetheminterpretedasfield

names.Forexample,thecalculation$(Tax,special)returnsthe

valueofafieldnamedTax,special.

Werecommendstronglythatyounamefieldswithoutusing

specialcharacters,namesoffunctions,oroperators(AND,OR,NOT,

XOR,TRUE,FALSE).

Thesameistrueforfieldsthatbeginwithaspace,aperiod,or

anumber:You'llhavetocontortyourcalculationstodealwith

them.Don'tusethem.Begineachfieldwithastandard

alphabeticalletteroranunderscore.



AddingFieldComments

Noticealsothatyoucanaddcommentstoyourfielddefinitions.

Wedon'tmeantobepedantic,butwewanttodrivehomethat

establishinggoodprogramminghabitswillserveyouwellfor

therestofyourlifeasadeveloper.Usethefieldcomments

feature.Explaintoyourselfayearfromnowwhyafieldexists,

anydependenciesorassumptionsyoumade,andpossiblyhow

youintendtouseit.



CreatingNewFields

TocreatefieldsinFileMakerPro,youneedtoentersometextin

theFieldNameareaoftheDefineDatabasedialogandclick

Create.

Oneimportantaspectofdatabasestokeepinmindisthatit's

importanttoestablishadiscretefieldforeachbitofinformation

youwanttostore.IfyoucreateafieldcalledContact

Informationandcramanentireaddressandasetofphone

numbersintoit,technicallyitwillworkfine,butifitevercomes

timetoexportthatinformation,sortbyareacode,orruna

reportbycity,youwon'tbeabletoculltheinformationyou

wantfromthefieldwithoutsufferingfromagoodheadache.

Todatabasewonks,theContactInformationexamplewouldbea

violationoffirstnormalform,ormorecolloquially,"onefact,onefield."

Forinformationonrelationaldatamodelinganddefiningfields,see

"RelationshipTypes,"p.136.







Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 3. Defining and Working with Fields

Tải bản đầy đủ ngay(0 tr)

×