You are on page 1of 10

VisualFoxProAccessingMySQL

presentedto TheAtlantaFoxProUsersGroup June19th,2007

ComparingMySQLwiththeVFPDBC,SQLServer, PostgreSQL
VFPDBCPros: 1. Veryfast 2. FreeDBCmultiuseraccessanddistribution 3. Transactions 4. ReferentialIntegrity 5. StoredProcedures 6. CanberunFROMavarietyoffileserversrunningvariousoperatingsystems 7. PoorODBCsupportbywebhostingcompanies 8. Officialsupportwillstopsometimeafter2015 9. Didwemention,veryfast! MySQLPros: 1. Multiuseraccess 2. Transactions 3. ReferentialIntegrity(recent) 4. StoredProcedures(recent) 5. Unlimiteddatabasesizes 6. Fast! 7. Free? 8. Availablewithcommon,inexpensivewebhostingplans 9. Canberunonavarietyofoperatingsystems SQLServerPros: 1. Multiuseraccess(notSQLExpress!) 2. Transactions 3. ReferentialIntegrity 4. StoredProcedures 5. Unlimiteddatabasesizes 6. Fast 7. Jobs PostgreSQLPros: 1. Free(reallyfree!)multiuseraccessanddistribution 2. Transactions 3. ReferentialIntegrity 4. StoredProcedures 5. Unlimiteddatabasesizes 6. Fast 7. Availablewithsome,inexpensivewebhostingplans 8. Canberunonavarietyofoperatingsystems 9. DidwementionFREE?!?

VFPCons: 1. 2Giglimit 2. Morenetworktraffic 3. Updatingdatabaseandtablestructuresdifficult MySQLCons: 1. RequiresaserverthatismorethanaFileServer 2. Maynotbefree? SQLServerCons: 1. RequiresaserverthatismorethanaFileServer 2. Notfree 3. Licensingpains 4. Closedsource 5. RequiresaMicrosoftWindowsserver 6. Youmaybeforcedtoupgradetokeepsupport PostgreSQLCons: 1. RequiresaserverthatismorethanaFileServer 2. Notascommonininexpensivewebhostingplans 3. GUItoolsmaynotbeasslickasotherofferings(Butwhocares,really.)

HowToInstallMySQL
Iwon'tgointotoomuchdetailhereabouthowtoinstallMySQL.Partlybecauseitissoeasy.Goto http://mysql.org/downloads/anddownloadtheserverforyourplatform.Makesuretocheckoutthe GUIToolssection.ItwillreallyhelpadministeryourMySQLinstallation.I'lltalkabouttheGUI toolsabitlater. AnotherapproachtotakeistotakealookatXAMPPathttp://www.apachefriends.org/en/xampp.html. XAMPPisasuiteofFOSSgoodnessthatincludesApache,MySQL,PHP,PHPmyAdminandother greatpackages.Allinoneeasytoinstallbundle.Recommended. OnenoteisthatXAMPPhastheINNODBengineturnedoffbydefault.You'llneedtoadjustthe my.cnffiletohaveitturnedon.Moreonthislater.

WhatGUItoolsareavailabletoAdministerandquery MySQL
ThereisnotashortageofGUItoolstohelpyouadministerandquerythedatathatyouhavestoredin MySQL.Herearejustacoupleofthetools.Somearecurrent,othersarebeingmoonlighted,and othersarestillinbeta. 1. MySQLAdministratorAnadministrativetoolthatenablesyoutocontrolyourenvironment andgainbettervisibilityintohowyourdatabasesareoperating.

2. MySQLControlCenterAnotheradministrativetoolthatallowsyoutocreateandmodifymost ofthedatabaseobjectsinatrivialmanner.

3. MySQLQueryBrowserOneoftheeasiesttoolsforcreating,executing,andoptimizingSQL queriesforyourdatabase.

4. PHPMyAdminAwebbasedadministrativetoolthatallowsyoutocreatedatabases,tables, indexes,administerrights,etc.Allinabrowser.

HowtoupsizeVFPstructuresanddatatoMySQL
1. UpsizingwizardinVFPrequiresaDBC 2. Stru2MySQL.prgbyEdLeafe. 3. Stru2MySQL_2.prgadditionsbyKevinCully ThechangesthatIhavemadetoStru2MySQLinclude: 1. Scriptfilesarecreatedforeachopencursor/table 2. Ascriptfileiscreatedthatcontainsalloftheindividualscriptfiles. 3. Theprogramcreatesanobject,thatcanhaveproperties/optionssettobettercontroltheoutput. 4. AdditionalMySQLcommandsareaddedtothescriptwhichdropsexistingtablesiftheyexist. 5. Theprogramallowsforalternativeenginestobespecified.INNODBvs.MyISAMasan example. I'llhavetheStru2MySQL_2.prguploadedbacktoEdLeafe'sdownloadspageat http://leafe.com/dls/vfp.Feelfreetomakeimprovementsanddonatebacktothecommunity.

ENGINEtalk
MySQLallowsfordifferentdatabasestobegovernedbydifferentengines.Twoofthemostpopularis MyISAMandINNODB.TobottomlinethedifferenceisthatMyISAMdoesnotsupporttransactions, whileINNODBdoes.Theperformancedifferencebetweenthetwoenginesisjustacoupleof percentagepoints,onewayortheotherbasedonmysimplebenchmarksthatIhaveperformed.There areotherbenchmarkstatisticsperformedbyfarsmarterandqualifiedpeoplethanmyself,sorunsome testsbeforeyougetstarted. RememberthatXAMPPhastheINNODBengineturnedoffbydefault.Aquickedittomy.cnfwilladd itbackinafterarestart.

Connecting,QueryingandupdatingdatafromVFP
TheconnectionstringtoMySQLlookssomethinglikethis: Driver={MySQLODBC3.51Driver};Port=3306;Server=192.168.1.128 ;Database=AFUG;Uid=afug;Pwd=afug12345 YoucanusetheSQLCONNECTandSQLEXECcommandcommandstogainaccesstoyourdatabases andtables.I'msorrythatthisissosparsehere,butI'mrunningoutoftime.Ifyou'veworkedwithany SQLServertypeserver,you'llhaveagreatstart.

EXPLAINingMySQL
ExplainisthekeytooltounderstandingtheexecutionplanoftheSQLoperations. Fromtheonlinehelp:WiththehelpofEXPLAIN,youcanseewhereyoushouldaddindexestotables togetafasterSELECTthatusesindexestofindrows.YoucanalsouseEXPLAINtocheckwhether theoptimizerjoinsthetablesinanoptimalorder. There'ssomuchhere,thatitisimpossibletogointoeverydetailabouthowtouseEXPLAINto optimizeoperations.ThegreatthingaboutMySQListhatthereissomuchhelpavailablefromthe MySQLfolksandothersaroundtheworld.That'stheendofthisEXPLAINation.

UsingthewwSQLclassfromWestWindtomakethings easier
WestWindWebConnectionisagreattoolforallsortsofdevelopmentefforts.I'mnotabigfanof views,orcursoradaptersinVFPdevelopment.IprefertheroughandtumbleSQLPassThrough(SPT) methodofmanipulatingdata.ThewwSQLclasshelpstakethepainoutofSPTforme.Therearetwo methodsinparticularthatreallyhelp:SQLBuildInsertStatementFromObjectand SQLBuildUpdateStatementFromObject.Thesemethodsacceptanobjectasthefirstparameter,andthe nameofthetargettableasthesecondparameter,andcreatesastringcontainingavalidINSERTor UPDATEcommandmatchingthecontentsoftheobject. Thereisaproblemhowever.WestWindtargetsthesemethodsateitherVFPtablesorSQLServer tables.TherearesomedifferencesbetweenSQLServerINSERTstatementsandMySQLINSERT statements.Iprobablyhaven'tfoundallofthedifferences,butthechangesareminor. Thebigdifferenceistherepresentationoftheemptydate.InSQLServer,theemptydatecanbe representedbytheemptystring.InMySQL,theemptydateisrepresentedbyaseriesofzerosinthe formatof'00000000'.WestWindalsowrapsfieldnamesinsquarebracketstohelpavoidproblems withspacesinfieldnames,andalsotoavoidproblemswithreservewords.InMySQL,fieldswrapped insquarebracketsthrowsanerror. So,IhavesubclassedthewwSQLclassandcreatedthreenewproperties:cEmptyDate, cFieldParamLeft,andcFieldParamRight.WheninuseagainstaMySQLtable,Ihavepopulated cEmptyDatewiththezeroformattedstringasabove,andsetthecFieldParamLeftand cFieldParamRightwiththeemptystringaswell. IthenoverrodetheSQLBuildInsertStatementFromObjectandthe SQLBuildUpdateStatementFromObjecttodrawfromthesepropertiesanditworkslikeacharm.Asa sidenote,IhavealsocreatedafunctionnamedDtoMySQLDate(toDateASDate)functionthatreturns adateformattedas'20070620'nomatterwhatSETDATEissetto.

IhopethatyouhavegottensometipsinhowtogetVFPtoaccessaMySQLserver.Onceyoutryit,I thinkyouwillfinditafast,robust,andinexpensivealternativetoothersolutions. Kevin

You might also like