OTL执行SQL语句的两种方式

OTL执行SQL语句的两种方式

1、使用otl_cursor::direct_exec(...)函数直接执行sql语句

例如otl_cursor::direct_exec(db,"create table ccc(aa int);");

 

2、使用otl_stream流执行sql语句使用步骤如下

 otl_stream otlCur(1,(const char*)str,db);
//或者
otl_stream otlCur;
otlCur.open(1,(const char*)str,db);//有点像fstream使用方式

2.1使用otl_stream流查询表以后把数据取出来的例子如下

int OTLSelete(otl_connect &db)
{
    try{

            // const char * str = "select aa from ccc where aa < 7 order by aa asc;";
            // const char * str = "select * from ccc;";
            const char * str = "select aa as ddd from ccc where aa < 7 ";
            otl_stream otlCur(1,(const char*)str,db);
            cout << " select result begin"<<endl;
            otl_column_desc* desc = NULL;
            int nlistlen = 1;
            desc=otlCur.describe_select(nlistlen); //取字段
            cout<<desc->name<<endl;
            while(!otlCur.eof())
            {
                int aa =0;
                // char *p=NULL;//error
                char p[64];

                otlCur>>aa;
                // otlCur>>p;
                cout <<" aa ="<< aa <<endl;
                // cout <<" bb ="<< p <<endl;
            }
            cout << " select result end"<<endl;
    }

有一篇不错的用法  https://blog.csdn.net/nie2314550441/article/details/49454311

C++交流群:585225803

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值