华为云云数据库GaussDB使用库函数_云淘科技
ECPGdebug(int on, FILE *stream):若函数第一个参数为非0,则开启调试日志。调试日志在标准输出流上执行,日志包含所有输入的SQL语句以及来自GaussDB Kernel服务器的结果。
示例:
#include #include #include #include "sqlca.h" int main() { ECPGdebug(1, stderr); EXEC SQL CONNECT postgres; EXEC SQL SET AUTOCOMMIT TO ON; EXEC SQL CREATE TABLE T1(a int); return (0); }
ECPGget_PGconn(const char *connection_name):返回由给定名称标识的数据库连接句柄。如果connection_name设置为NULL,则返回当前连接句柄;如果没有连接句柄可以被识别,则该函数返回NULL。
示例:
#include #include #include #include "sqlca.h" int main() { ECPGdebug(1, stderr); EXEC SQL CONNECT TO postgres as con1; EXEC SQL SET AUTOCOMMIT TO ON; EXEC SQL DROP TABLE IF EXISTS T1; PGconn *conn; conn = ECPGget_PGconn("con1"); printf("conn = %p ", conn); conn = ECPGget_PGconn(NULL); printf("conn = %p ", conn); EXEC SQL CREATE TABLE T1(a int); return (0); }
ECPGtransactionStatus(const char *connection_name):返回connection_name连接的当前事务状态。
示例:
#include #include #include #include "sqlca.h" int main() { ECPGdebug(1, stderr); EXEC SQL CONNECT TO postgres as con1; EXEC SQL DROP TABLE IF EXISTS T1; int a = ECPGtransactionStatus("con1"); printf("%d ", a); EXEC SQL CREATE TABLE T1(a int); EXEC SQL COMMIT; return (0); }
ECPGfree_auto_mem():释放为输出型宿主变量申请的所有内存,在程序结束时调用(return\exit)。
示例:
#include #include #include #include "sqlca.h" int main() { EXEC SQL BEGIN DECLARE SECTION; int *ip1=0; char **cp2=0; int *ipointer1=0; int *ipointer2=0; int colnum; EXEC SQL END DECLARE SECTION; int i; ECPGdebug(1, stderr); EXEC SQL WHENEVER SQLERROR DO sqlprint(); EXEC SQL CONNECT TO REGRESSDB1; EXEC SQL SET DATESTYLE TO postgres; EXEC SQL CREATE TABLE test (a int, b text); EXEC SQL INSERT INTO test VALUES (1, 'one'); EXEC SQL INSERT INTO test VALUES (2, 'two'); EXEC SQL INSERT INTO test VALUES (NULL, 'three'); EXEC SQL INSERT INTO test VALUES (NULL, NULL); EXEC SQL ALLOCATE DESCRIPTOR mydesc; EXEC SQL SELECT * INTO SQL DESCRIPTOR mydesc FROM test; EXEC SQL GET DESCRIPTOR mydesc :colnum=COUNT; EXEC SQL GET DESCRIPPTOR mydesc VALUE 1 :ip1=DATA, :ipointer1=INDICATOR; EXEC SQL GET DESCRIPTOR mydesc VALUE 2 :cp2=DATA, :ipointer2=INDICATOR; printf("Result (%d columns): ", colnum); for (i=0;i < sqlca.sqlerrd[2];++i) { if (ipointer1[i]) printf("NULL, "); else printf("%d, ",ip1[i]); if (ipointer2[i]) printf("NULL, "); else printf("'%s', ",cp2[i]); printf(" "); } ECPGfree_auto_mem(); printf(" "); EXEC SQL DEALLOCATE DESCRIPTOR mydesc; EXEC SQL ROLLBACK; EXEC SQL DISCONNECT; return 0; }
父主题: 基于ecpg开发
同意关联代理商云淘科技,购买华为云产品更优惠(QQ 78315851)
内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家