已阅读5页,还剩26页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 ALTIBASE开发培训 天津南开创元信息技术有限公司韩国Altibase公司 2 CONTENTS 1 AltibaseCLI 3 1 AltibaseCLI CLIOverviewCLIAPIGroupsBasicProgrammingStepsNoteswhenimplementingProgramsSample Basic 4 Overview 1 CallLevelInterfaceCLIIsStandard AltibaseCLIcomplieswithX OPENCLIstandardspecification Soyoucanfindeasilyusefulsampleanddocumentsex Altibase MSDN ODBC DB2 Informix Postgres Enablesyoutowritedatabaseindependentapplications 5 Overview 2 DifferencebetweenCLIandEmbeddedSQL Ex SQLExecDirect stmt deletefromt1 SQL NTS EXECSQLdeletefromT1 E SQL SESC ProC needsprecompilestep Belowtwothingsismypersonalopinions E SQLismoreeasyindevelopmentandsourcereadability InC Object OrientedStyledevelopmethod CLIcanbemoregoodchoicethanE SQL 6 Overview 3 CLIAPIFunctionsGroupsEnvironment ConnectionManagementex SQLAllocEnv SQLDriverConnect SQLStatementProcessingex SQLPrepare SQLExecute AttributeProcessingex SQLSetConnectAttr SQLSetStmtAttr MetaInformationProcessingex SQLTables CLIAPIGroups 1 Environment ConnectionManagement SQLStatementProcessing SQLAllocEnv SQLAllocConnect SQLAllocStmt SQLFreeEnv SQLFreeConnect SQLFreeStmt SQLDriverConnectSQLConnectSQLDisconnect SQLPrepare SQLBindParameter SQLExecute SQLNumResultColsSQLDescribeColSQLRowCountSQLGetData SQLBindColSQLFetchSQLExecDirectSQLEndTran 8 AttributeProcessing MetaInformationProcessing SQLSetEnvAttr SQLSetConnectAttr SQLSetStmtAttr ex ArrayInsert Update SQLTablesSQLColumnsSQLProcedures SQLPrimaryKeysSQLForeignKeysSQLStatistics CLIAPIGroups 2 SQLProcedureColumnsSQLSpecialColumnsSQLTablePrivilegs 9 SQLRETURNSQLAllocEnv SQLHENV env rc SQLAllocEnv Allocatesanenvironmenthandleandassociatedresources if rc SQL SUCCESS Environment ConnectionManagement 1 SQLRETURNSQLAllocConnect SQLHENVenv SQLHDBC dbc rc SQLAllocConnect henv Allocatesaconnectionhandleandassociatedresourcesif rc SQL SUCCESS SQLRETURNSQLAllocStmt SQLHDBCDBC SQLHSTMT stmt rc SQLAllocStmt Allocatesanewstatementhandleand associatesitwiththeconnectionspecifiedbytheconnectionhandle if rc SQL SUCCESS 10 SQLRETURNSQLFreeEnv SQLHENVenv SQLRETURNSQLFreeConnect SQLHDBCdbc SQLRETURNSQLFreeStmt SQLHSTMTstmt SQLSMALLINTfOption rc SQLFreeStmt hstmt SQL DROP Freesastatementhandleif rc SQL SUCCESS rc SQLDisconnect hdbc Closestheconnectionassociatedwiththedatabaseconnectionhandle if rc SQL SUCCESS printf DisconnectError n SQLFreeConnect hdbc Invalidatesandfreestheconnectionhandle SQLFreeEnv henv Invalidatesandfreestheenvironmenthandle Environment ConnectionManagement 2 11 SQLRETURNSQLDriverConnect SQLHDBCdbc SQLHWNDwindowHandle NotUsed SQLCHAR InConnectionString SQLSMALLINT length1 SQLCHAR OutConnectionString SQLSMALLINTbufferLength SQLSMALLINT strlength2Ptr SQLSMALLINT DriverCompletion charconnstr 100 sprintf connstr DSN s UID s PWD s CONNTYPE 1 PORT NO s server uid pwd port rc SQLDriverConnect hdbc NULL connstr SQL NTS NULL 0 NULL SQL DRIVER NOPROMPT if rc SQL SUCCESS Environment ConnectionManagement 3 12 sprintf sql SELECTENAMEFROMEMPLOYEEWHERENAME rc SQLPrepare hstmt1 sql SQL NTS SQLStatementProcessingExamples 1 SQLRETURNSQLPrepare SQLHSTMTstmt SQLCHAR sql SQLINTEGERsqlLength SQLRETURNupd execute intpos if chk stmt u NOT YET PREPARED rc upd prepare performancefactor if SQLExecute stmt u SQL SUCCESS unicom upd ins cli app1 cpp 13 SQLRETURNSQLBindParameter SQLHSTMTStatementHandle SQLSMALLINTParameterNumber SQLSMALLINTpType SQLSMALLINTcType SQLSMALLINTsqlType SQLINTEGERcolumnSize SQLSMALLINTscale numeric columnSize scale SQLPOINTERParameterValuePtr SQLINTEGERBufferLength sizeof ParameterValuePrt SQLINTEGER StrLen or IndPtr when 1meansNULLvalueSQL NULL DATA 1 SQLStatementProcessingExamples 2 rc SQLBindParameter hstmt1 1 SQL PARAM INPUT SQL C CHAR SQL VARCHAR ID LEN 0 id sizeof id NULL if rc SQL SUCCESS 14 Correcttypematchingismajorperformancefator integer smallint bigintdatatypesshowfasterperformancethannumeric Speciallyintheindexcolumn numerictypehavebigtypeconversioncost SQLStatementProcessingExamples 3 15 SQLRETURNSQLBindCol SQLHSTMTstmt SQLSMALLINTColumnNumber SQLSMALLINTTargetType SQLPOINTERTargetValuePtr SQLINTEGERBufferLength SQLINTEGER StrLen or IndPtr SQLRETURNSQLFetch SQLHSTMTstmt SQLStatementProcessingExamples 4 16 SQLExecDirect Thisisjustsample Don tuseSQLExecDirectforperformancehstmt2 selectid namefromemployee SQL NTS if SQL SUCCESS SQLBindCol hstmt2 1 SQL C CHAR id 8 NULL if SQL SUCCESS SQLBindCol hstmt2 2 SQL C CHAR name 30 SQLStatementProcessingExamples 5 BasicProgrammingSteps 1 CLIApplicationcontains InitializationTransactionProcessingTerminationDiagnosticMessageHandling 18 STEP1 CONNECTSQLAllocHandle env SQLAllocEnvSQLSetEnvAttrSQLAllocHandle dbc SQLAllocConnectSQLDriverConnectSQLSetConnectAttr setnon autocommit BasicProgrammingSteps STEP2 INITIALIZESQLAllocHandle stmt SQLAllocStmtSQLSetStmtAttr whenarraybinding BasicProgrammingSteps 2 19 STEP3 ExecuteMetaCatalogfunctionOrSQLExecute SQLExecDirect 1 SelectorMetaCatalog STEP4a FetchResultsSQLNumResultColsSQLDescribeColSQLBindColSQLFetchSQLGetData STEP4b FetchRowCountSQLRowCount Non array affectedresultnum 2 Update Delete Insert 3 Other BasicProgrammingSteps 3 20 STEP5 TRANSACTSQLEndTran STEP6 DISCONNECTSQLFreeHandle stmt SQLFreeStmtSQLDisconnectSQLFreeHandle dbc SQLFreeConnectSQLFreeHandle env SQLFreeEnv BasicProgrammingSteps 4 21 NotesWhenImplementingPrograms 1 Step1 Formulti threadprogram thefunctionideAllocErrorSpace shouldbecalledinthreadmainfunctionbeforeotherDBfunctions Formulti threadprogram thesameconnectionhandlemustnotbeusedonothertheads CLIAPIisnotsafeinSignal Don tuseSignal ifitisneeded thenusethread if 0 pthread create sample SQLCLI demo mt cpp 22 NotesWhenImplementingPrograms 2 Step2 InSQLBindCol orSQLBindParameter thelastparametervalueLength lStrLen or IndPtr isindicatorvariabletocheck NULLorNotNULL Step3 WhenyouexitaprogramwithoutexecutingtheCOMMITstatementinAUTOCOMMITOFFsession SQLstatementsthatyoucannotfinishareallROLLBACKed ButiftheprogramexitsafterexecutingtheSQLDisconnect theCOMMITstatementisperformed 23 Step4 InSQLFreeStmt RememberthedifferencebetweenSQL DROPandSQL CLOSE SQL DROPReleaseallresourceofthestatement Forreuse firstlySQLAllocStmtisneeded SQL CLOSECheckdemo ex2 cpp Thisisusedforreleasenon endedfetchresultonly NotesWhenImplementingPrograms 3 24 SQLFreeStmt stmt SQL CLOSE Ifacursorfetchedthelastrecordofaresultset SQL CLOSEcanbeomitted Howerver iftherearesomerecordstobefetchedbySQLFetch andSQLExecute isre executed invalidcusorerroroccurs sample SQLCLI demo ex2 cpp NotesWhenImplementingPrograms 4 25 include include include defineSQL LEN1000 defineMSG LEN1024SQLHENVenv Allocatesanenvironmenthandle SQLHDBCdbc Allocatesanconnectionhandle intconn flag intexecute type SQLRETURNalloc handle SQLRETURNdb connect voidfree handle SQLRETURNexecute select voidexecute err SQLHDBCaCon SQLHSTMTaStmt char q Sample Basic 1 26 intmain SQLRETURNrc env SQL NULL HENV dbc SQL NULL HDBC conn flag 0 execute type 1 Allocatesthehandle rc alloc handle if rc SQL SUCCESS free handle exit 1 rc db connect if rc SQL SUCCESS free handle exit 1 Sample Basic 1 Tasks switch execute type case1 rc execute select break case1 rc execute insert break case1 rc execute update break case1 rc execute delete break if rc SQL SUCCESS printf Successexecute free handle 27 voidexecute err SQLHDBCaCon SQLHSTMTaStmt char q SQLINTEGERSQLCODE SQLCHARSQLSTATE 7 SQLSMALLINTmsgLength
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 快递行业客户投诉处理流程标准
- 企业供应商准入标准流程
- 大学生四季家风征文范例汇编
- 三年级数学期末考试分析报告
- 三年级语文部编版第三单元知识点总结
- 大学英语六级词汇记忆技巧
- 施工现场文明管理体系解读
- 小学三年级学生想象作文评语范例
- 机械设备操作说明与安全规范
- 宫颈癌预防与健康宣教手册
- 常见疑似预防接种异常反应诊治原则课件
- 年小区业委会工作经费预算说明
- 动火证施工现场动火证申请书
- 八年级数学上册整式的乘法多项式乘以多项式
- YS/T 781.4-2012铝及铝合金管、棒、型材行业清洁生产水平评价技术要求第4部分:氟碳漆喷涂产品
- GB/T 20220-2006塑料薄膜和薄片样品平均厚度、卷平均厚度及单位质量面积的测定称量法(称量厚度)
- 04-电缆绝缘电阻测试记录表
- 《罗织经》全文及翻译
- 心脏肿瘤及心内异常回声
- (中职)计算机组装与维护第7章 电源和机箱教学课件
- 旅游情景英语课件(完整版)
评论
0/150
提交评论