达梦有仿照OCI(Oracle Call Interface)实现了一套DCI 的接口实现。具体在 DM_program p261 中有说明。我照着这个实现编译了下,发现可能依文档编译时有点问题,把有问题的地方改了下,记录在这。 VS 设置: 常规 - 输出目录 - c:\dmdbms\bin 备注: 为了省事这
达梦有仿照OCI(Oracle Call Interface)实现了一套DCI 的接口实现。具体在 > p261
中有说明。我照着这个实现编译了下,发现可能依文档编译时有点问题,把有问题的地方改了下,记录在这。
VS 设置:
常规 -> 输出目录 -> c:\dmdbms\bin
备注: 为了省事这样弄的,实际发布时,把C:\dmdbms\bin下的.dll文件都复制过去就行了。
C/C++ -> 常规 -> 附加包含目录 -> c:\dmdbms\include 链接器 -> 附加库目录 -> c:\dmdbms\include 链接器 -> 附加依赖项 -> dmoci.lib
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <malloc.h> #include "DCI.h" /* 声明句柄 */ OCIEnv *envhp; /* 环境句柄 */ OCISvcCtx *svchp; /* 服务环境句柄 */ OCIServer *srvhp; /* 服务器句柄 */ OCISession *authp; /* 会话句柄 */ OCIStmt *stmthp; /* 语句句柄 */ OCIDescribe *dschp; /* 描述句柄 */ OCIError *errhp; /* 错误句柄 */ OCIDefine *defhp[3]; /* 定义句柄 */ OCIBind *bidhp [4]; /* 绑定句柄 */ sb2 ind[3]; /* 指示符变量 */ /* 绑定select结果集的参数 */ text szpersonid[11]; /* 存储personid列 */ text szsex[2]; /* 存储sex列 */ text szname[51]; /* 存储name列 */ text szemail[51]; /* 存储mail列 */ text szphone[26]; /* 存储phone列 */ char sql[256] = {0}; /* 存储执行的sql语句*/ int DMDemo(); int main() { DMDemo(); system("pause"); return 0; } int DMDemo() { char strServerName[50]; char strUserName[50]; char strPassword[50]; /* 设置服务器,用户名和密码 */ strcpy(strServerName,"localhost"); strcpy(strUserName,"SYSDBA"); strcpy(strPassword,"111111"); //SYSDBA /* 初始化OCI应用环境*/ OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL); /* 初始化环境句柄 */ OCIEnvInit(&envhp, OCI_DEFAULT,0, 0); /* 分配句柄 */ OCIHandleAlloc(envhp, (dvoid**)&svchp, OCI_HTYPE_SVCCTX, 0, 0); /* 服务器环境句 柄 */ OCIHandleAlloc(envhp, (dvoid**)&srvhp, OCI_HTYPE_SERVER, 0, 0); /* 服务器句柄 */ OCIHandleAlloc(envhp, (dvoid**)&authp, OCI_HTYPE_SESSION, 0, 0); /* 会话句柄 */ OCIHandleAlloc(envhp, (dvoid**)&errhp, OCI_HTYPE_ERROR, 0, 0); /* 错误句柄 */ OCIHandleAlloc(envhp, (dvoid**)&dschp, OCI_HTYPE_DESCRIBE,0,0); /* 描述符句柄 */ /* 连接服务器 */ OCIServerAttach(srvhp, errhp,(text *)strServerName, (sb4)strlen(strServerName),OCI_DEFAULT ) ; /* 设置用户名和密码 */ OCIAttrSet(authp,OCI_HTYPE_SESSION,(text *)strUserName, (ub4)strlen(strUserName),OCI_ATTR_USERNAME,errhp); OCIAttrSet(authp,OCI_HTYPE_SESSION,(text *)strPassword, (ub4)strlen(strPassword), OCI_ATTR_PASSWORD,errhp); /* 设置服务器环境句柄属性 */ OCIAttrSet ((dvoid*)svchp, (ub4) OCI_HTYPE_SVCCTX, (dvoid*)srvhp, (ub4) 0, OCI_ATTR_SERVER, errhp); OCIAttrSet(svchp, OCI_HTYPE_SVCCTX,(dvoid*)authp, 0, OCI_ATTR_SESSION, errhp); /* 创建并开始一个用户会话 */ OCISessionBegin (svchp, errhp, authp,OCI_CRED_RDBMS,OCI_DEFAULT); OCIHandleAlloc(envhp, (dvoid**)&stmthp,OCI_HTYPE_STMT, 0, 0); /* 语句句柄 */ /************************************************************************/ /* 查询person 表 */ /************************************************************************/ strcpy(sql, "select personid, name, phone from person.person;"); /* 准备SQL 语句 */ OCIStmtPrepare(stmthp, errhp,(text *)sql, strlen(sql),OCI_NTV_SYNTAX, OCI_DEFAULT); /* 绑定输出列 */ OCIDefineByPos(stmthp,&defhp[0],errhp, 1,(ub1*)szpersonid, sizeof(szpersonid),SQLT_STR,&ind[0], 0, 0, OCI_DEFAULT); OCIDefineByPos (stmthp,&defhp[1],errhp, 2,(ub1*)szname, sizeof(szname),SQLT_STR,&ind[1], 0, 0, OCI_DEFAULT); OCIDefineByPos (stmthp,&defhp[ 2],errhp, 3,(ub1*)szphone, sizeof(szphone),SQLT_STR,&ind[2], 0, 0, OCI_DEFAULT); /* 执行SQL 语句 */ OCIStmtExecute(svchp, stmthp,errhp, (ub4)0, 0, NULL, NULL, OCI_DEFAULT); printf("% -10s%-10s%-10s\n", "PERSONID", "NAME", "PHONE"); while((OCIStmtFetch( stmthp, errhp,1,OCI_FETCH_NEXT,OCI_DEFAULT))!=OCI_NO_DATA) { printf("% -10s", szpersonid); printf("% -10s", szname); printf("% -10s\n", szphone); } /************************************************************************/ /* 向person 表插入一条数据 */ /************************************************************************/ memset(sql, 0, sizeof(sql)); strcpy(sql, "insert into person.person(sex, name, email, phone) values(:sex,:name,:email,:phone);"); /* 准备SQL 语句 */ OCIStmtPrepare(stmthp, errhp,(text *)sql, strlen(sql),OCI_NTV_SYNTAX, OCI_DEFAULT); /* 绑定输入列 */ const OraText col_sex[] = ":sex"; const OraText col_name[] = ":name"; const OraText col_email[] = ":email"; const OraText col_phone[] = ":phone"; OCIBindByName(stmthp, &bidhp[0], errhp, col_sex, 4, szsex, sizeof(szsex),SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); OCIBindByName(stmthp, &bidhp[1], errhp, col_name, 5, szname, sizeof(szname), SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); OCIBindByName(stmthp, &bidhp[2], errhp, col_email, 6, szemail, sizeof(szemail),SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); OCIBindByName(stmthp, &bidhp[3], errhp, col_phone, 6, szphone, sizeof(szphone),SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); //OCIBindByName(stmthp, &bidhp[0], errhp, ":sex", 4, szsex, sizeof(szsex),SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); //OCIBindByName(stmthp, &bidhp[1], errhp, ":name", 5, szname, sizeof(szname), SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); //OCIBindByName (stmthp, &bidhp[2], errhp, ":email", 6, szemail, sizeof(szemail),SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); //OCIBindByName (stmthp, &bidhp[3], errhp, ":phone", 6, szphone, sizeof(szphone),SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); /* 设置输入参数 */ memset(szsex, 0, sizeof(szsex)); //strcpy(szsex, "M"); memcpy(szsex,"M",strlen("M")+1); memset(szname, 0, sizeof(szname)); //strcpy(szname, " 张三"); memcpy(szname,"张三",strlen("张三")+1); memset(szemail, 0, sizeof(szemail)); //strcpy(szemail, "zhangsan@dameng.com"); memcpy(szemail,"zhangsan@dameng.com",strlen("zhangsan@dameng.com")+1); memset(szphone, 0, sizeof(szphone)); memcpy(szphone,"027-87588000",strlen("027-87588000")+1); //strcpy(szphone, "027-87588000"); /* 执行SQL 语句 */ OCIStmtExecute(svchp, stmthp, errhp, (ub4)0, (ub4) 0, (CONST OCISnapshot*) 0, (OCISnapshot*) 0,(ub4) OCI_DEFAULT); /* 提交到数据库 */ OCITransCommit(svchp, errhp, OCI_DEFAULT); /************************************************************************/ /* 更新person 表 */ /************************************************************************/ memset(sql, 0, sizeof(sql)); strcpy(sql, "update person.person set sex='M',name='Liuhuan',email='liujian@mail',phone='13636396811' WHERE personid=1"); /* 准备SQL 语句 */ OCIStmtPrepare(stmthp, errhp,(text *)sql, strlen(sql),OCI_NTV_SYNTAX, OCI_DEFAULT); /* 执行SQL 语句 */ OCIStmtExecute (svchp, stmthp, errhp, (ub4)0, (ub4) 0, (CONST OCISnapshot*) 0, (OCISnapshot*) 0,(ub4) OCI_DEFAULT); /* 提交到数据库 */ OCITransCommit(svchp, errhp, OCI_DEFAULT); /************************************************************************/ /* 删除person 表的ID为的数据,首先要在数据库中存在这条记录 */ /************************************************************************/ memset(sql, 0, sizeof(sql)); strcpy(sql, "delete from person.person WHERE personid=?"); /* 准备SQL 语句 */ OCIStmtPrepare(stmthp, errhp,(text *)sql, strlen(sql),OCI_NTV_SYNTAX, OCI_DEFAULT); /* 绑定输入参数 */ memset(szpersonid, 0, sizeof(szpersonid)); memcpy(szpersonid,"20",strlen("20")+1); //strcpy(szpersonid, "20"); OCIBindByPos(stmthp, &bidhp[0], errhp, 1, szpersonid, sizeof(szpersonid),SQLT_AFC, NULL, NULL, NULL, 0, NULL, 0); /* 执行SQL 语句 */ OCIStmtExecute(svchp, stmthp, errhp, (ub4)0, (ub4) 0, (CONST OCISnapshot*) 0, (OCISnapshot*) 0, (ub4) OCI_DEFAULT); /* 提交到数据库 */ OCITransCommit(svchp, errhp, OCI_DEFAULT); // 结束会话 OCISessionEnd(svchp, errhp, authp, (ub4) 0); // 断开与数据库的连接 OCIServerDetach(srvhp, errhp, OCI_DEFAULT); // 释放OCI句柄 OCIHandleFree((dvoid*)dschp, OCI_HTYPE_DESCRIBE); OCIHandleFree((dvoid*)stmthp, OCI_HTYPE_STMT ); OCIHandleFree((dvoid*)errhp, OCI_HTYPE_ERROR); OCIHandleFree((dvoid*)authp, OCI_HTYPE_SESSION ); OCIHandleFree(( dvoid*)svchp, OCI_HTYPE_SVCCTX); OCIHandleFree((dvoid*)srvhp, OCI_HTYPE_SERVER); return 0; }

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.