SQL数据库中英文对照外文翻译文献.docx
《SQL数据库中英文对照外文翻译文献.docx》由会员分享,可在线阅读,更多相关《SQL数据库中英文对照外文翻译文献.docx(22页珍藏版)》请在冰豆网上搜索。
SQL数据库中英文对照外文翻译文献
中英文对照外文翻译文献
(文档含英文原文和中文翻译)
WorkingwithDatabases
ThischapterdescribeshowtouseSQLstatementsinembeddedapplicationstocontroldatabases.Therearethreedatabasestatementsthatsetupandopendatabasesforaccess:
SETDATABASEdeclaresadatabasehandle,associatesthehandlewithanactualdatabasefile,andoptionallyassignsoperationalparametersforthedatabase.
SETNAMESoptionallyspecifiesthecharactersetaclientapplicationusesforCHAR,VARCHAR,andtextBlobdata.Theserverusesthisinformationtotransliteratefromadatabase’sdefaultcharactersettotheclient’scharactersetonSELECToperations,andtotransliteratefromaclientapplication’scharactersettothedatabasecharactersetonINSERTandUPDATEoperations.
gCONNECTopensadatabase,allocatessystemresourcesforit,andoptionallyassignsoperationalparametersforthedatabase.Alldatabasesmustbeclosedbeforeaprogramends.AdatabasecanbeclosedbyusingDISCONNECT,orbyappendingtheRELEASEoptiontothefinalCOMMITorROLLBACKinaprogram.
Declaringadatabase
Beforeadatabasecanbeopenedandusedinaprogram,itmustfirstbedeclaredwithSETDATABASEto:
CHAPTER3WORKINGWITHDATABASES.Establishadatabasehandle.Associatethedatabasehandlewithadatabasefilestoredonalocalorremotenode.Adatabasehandleisaunique,abbreviatedaliasforanactualdatabasename.DatabasehandlesareusedinsubsequentCONNECT,COMMITRELEASE,andROLLBACKRELEASEstatementstospecifywhichdatabasestheyshouldaffect.ExceptindynamicSQL(DSQL)applications,databasehandlescanalsobeusedinsidetransactionblockstoqualify,ordifferentiate,tablenameswhentwoormoreopendatabasescontainidenticallynamedtables.
Eachdatabasehandlemustbeuniqueamongallvariablesusedinaprogram.Databasehandlescannotduplicatehost-languagereservedwords,andcannotbeInterBasereservedwords.Thefollowingstatementillustratesasimpledatabasedeclaration:
EXECSQL
SETDATABASEDB1=’employee.gdb’;
Thisdatabasedeclarationidentifiesthedatabasefile,employee.gdb,asadatabasetheprogramuses,andassignsthedatabaseahandle,oralias,DB1.
Ifaprogramrunsinadirectorydifferentfromthedirectorythatcontainsthedatabasefile,thenthefilenamespecificationinSETDATABASEmustincludeafullpathname,too.Forexample,thefollowingSETDATABASEdeclarationspecifiesthefullpathtoemployee.gdb:
EXECSQL
SETDATABASEDB1=’/interbase/examples/employee.gdb’;
Ifaprogramandadatabasefileitusesresideondifferenthosts,thenthefilenamespecificationmustalsoincludeahostname.ThefollowingdeclarationillustrateshowaUnixhostnameisincludedaspartofthedatabasefilespecificationonaTCP/IPnetwork:
EXECSQL
SETDATABASEDB1=’jupiter:
/usr/interbase/examples/employee.gdb’;
OnaWindowsnetworkthatusestheNetbeuiprotocol,specifythepathasfollows:
EXECSQL
SETDATABASEDB1=’//venus/C:
/Interbase/examples/employee.gdb’;
DECLARINGADATABASE
EMBEDDEDSQLGUIDE37
Declaringmultipledatabases
AnSQLprogram,butnotaDSQLprogram,canaccessmultipledatabasesatthesametime.Inmulti-databaseprograms,databasehandlesarerequired.Ahandleisusedto:
1.Referenceindividualdatabasesinamulti-databasetransaction.
2.Qualifytablenames.
3.SpecifydatabasestoopeninCONNECTstatements.
IndicatedatabasestoclosewithDISCONNECT,COMMITRELEASE,andROLLBACKRELEASE.
DSQLprogramscanaccessonlyasingledatabaseatatime,sodatabasehandleuseisrestrictedtoconnectingtoanddisconnectingfromadatabase.
Inmulti-databaseprograms,eachdatabasemustbedeclaredinaseparateSETDATABASEstatement.Forexample,thefollowingcodecontainstwoSETDATABASEstatements:
...
EXECSQL
SETDATABASEDB2=’employee2.gdb’;
EXECSQL
SETDATABASEDB1=’employee.gdb’;
...
4Usinghandlesfortablenames
Whenthesametablenameoccursinmorethanonesimultaneouslyaccesseddatabase,adatabasehandlemustbeusedtodifferentiateonetablenamefromanother.Thedatabasehandleisusedasaprefixtotablenames,andtakestheformhandle.table.
Forexample,inthefollowingcode,thedatabasehandles,TESTandEMP,areusedtodistinguishbetweentwotables,eachnamedEMPLOYEE:
...
EXECSQL
DECLAREIDMATCHCURSORFOR
SELECTTESTNOINTO:
matchidFROMTEST.EMPLOYEE
WHERETESTNO>100;
EXECSQL
DECLAREEIDMATCHCURSORFOR
SELECTEMPNOINTO:
empidFROMEMP.EMPLOYEE
WHEREEMPNO=:
matchid;
...
CHAPTER3WORKINGWITHDATABASES
38INTERBASE6
IMPORTANT
ThisuseofdatabasehandlesappliesonlytoembeddedSQLapplications.DSQLapplicationscannotaccessmultipledatabasessimultaneously.
4Usinghandleswithoperations
Inmulti-databaseprograms,databasehandlesmustbespecifiedinCONNECTstatementstoidentifywhichdatabasesamongsever