linux c api连接数据库代码怎么变成occi方式代码

C语言 码拜 9年前 (2015-10-24) 1420次浏览
#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <signal.h>

#include <time.h>

#include <sys/time.h>

#include <string.h>

#include “mysql.h”
#define _GNU_SOURCE
MYSQL *my_connection;

MYSQL_RES *result, *results;

//results 直流 result 整车

MYSQL_RES *res1;

MYSQL_ROW sql_row;

int res, sqln;
void handler()

{

/*

char Times[1024];

struct tm *newtime;

char tmpbuf[128];

string str;

time_t lt1;

time( &lt1 );

newtime=localtime(&lt1);

strftime( Times, seizeof(Times),”  %x %X   “, newtime);

str=Times;

*/

struct tm tm_time;

char szBuf[256] = {0};

time_t timer = time(NULL);

strftime(szBuf, sizeof(szBuf), “%Y-%m-%d %H:%M:%S”, localtime(&timer));

printf(“%s/n”, szBuf);
/* sqln = mysql_query(my_connection,”inser into M_CHARGE_VOLT A(A.CHARGE_NO, A.DATA_DATE , A.VOLTAGE)

VALUES(res1,to_date ( “szBuf” , “”YYYY-MM-DD HH24:MI:SS”” )  , “”0″”)”);

*/

signal(SIGALRM,handler);

alarm(1800);

}

int main()

{

my_connection = mysql_init(NULL);

if (mysql_real_connect(my_connection, “127.0.0.1”, “sys”, “as sysdba”, “ORCL”, 3306, NULL, 0))

{

perror(“connect..\n”);

mysql_query(my_connection,”set names gbk”);

res = mysql_query(my_connection, “select * from M_VEH_CHARGE_REAL  “);

if (res)

{

printf(“执行显示时出现异常: %s”,mysql_error(my_connection));

result=mysql_store_result(my_connection);

if(result)

{

sqln = mysql_query(my_connection , “select CHARGEPOLE_NO from M_CHARGEPOLE_REAL “);//思路:整车的id 跟 直流 要一对一插入
sqln = mysql_query(my_connection, “insert into M_VEH_CHARGE_REAL B( B.CHARGE_NO , B.YGZDD , B.CHARGE_STATUS , B.CHARGE_TIME , B.POWER_STATION_NO , B.WHETHER_BATTERY , B.VOLT , B.CUR)

select A.CHARGEPOLE_NO , A.YGZDD, A.CHARGEPOLE_STATUS, A.CHARGE_TIME, A.POWER_STATION_NO, A.WHETHER_BATTERY, A.VOLT, A.CUR from M_CHARGEPOLE_REAL A  WHERE  A.CHARGEPOLE_NO IN

(select EQUIP_NO from D_STAKE_ARCH where STAKE_PARA_ID = “”3″”)”);//插入表M_CHARGEPOLE_REAL的全部行

sqln = mysql_query(my_connection ,”select , EQUIP_NO from D_CHG_ENG_ARCH where CHG_ENG_PARA_ID = “”5″” ORDER BY EQUIP_NO “);

result = mysql_store_result(my_connection);

sqln = mysql_query(my_connection ,”select , EQUIP_NO from D_STAKE_ARCH where STAKE_PARA_ID = “”3″”ORDER BY EQUIP_NO “);

results = mysql_store_result(my_connection);

while(sql_row = mysql_fetch_row(result))

{

for(int t =0;t<<mysql_num_fields(result);t++)

{

//sqln = mysql_query(my_connection ,”update M_VEH_CHARGE_REAL A set A.CHARGE_NO = “results[t]” where charge_no =”result[i]);

//sqln = mysql_query(my_connection,”upate M_VEH_CHARGE_REAL C set C.BATTERYGROUP_MAX_TEMP= 0 , C.BMS_BUG = “”0″”, C.PASS_BUG = “”0″”, C.HARDWARE_BUG = “”0″”, C.OVER_CHARGE = “”0″” where chargepole_no = “result[i] );

}
}
sqln = mysql_query(my_connection , “insert into M_VEH_CHARGE_REAL B( B.CHARGE_NO , B.YGZDD , B.CHARGE_STATUS , B.CHARGE_TIME , B.POWER_STATION_NO , B.WHETHER_BATTERY , B.VOLT , B.CUR) VALUES (select C.CHARGEPOLE_NO , A.YGZDD, A.CHARGEPOLE_STATUS, A.CHARGE_TIME, A.POWER_STATION_NO, A.WHETHER_BATTERY, A.VOLT, A.CUR from (select * ,rownum n , from M_CHARGEPOLE_REAL  WHERE  CHARGEPOLE_NO IN (select EQUIP_NO from D_STAKE_ARCH where STAKE_PARA_ID = “”3″”) order by EQUIP_NO ) A , (select CHARGEPOLE_NO,rownum n  from D_CHG_ENG_ARCH order by EQUIP_NO) C  WHERE A.n = C.n) “);
}

else

{
/*sqln = mysql_query(my_connection,”UPDATE M_VEH_CHARGE_REAL a SET (a.YGZDD,a.CHARGE_STATUS,a.CHARGE_TIME, a.POWER_STATION_NO,a.WHETHER_BATTERY,a.VOLT ,a.CUR) =( SELECT b.YGZDD, CHARGEPOLE_STATUS, b.CHARGE_TIME, b.POWER_STATION_NO, b.WHETHER_BATTERY, b.VOLT, b.CUR

FROM M_CHARGEPOLE_REAL b

WHERE a.CHARGE_NO = b.CHARGEPOLE_NO)

where exists

( SELECT 1 from M_CHARGEPOLE_REAL b where a.CHARGE_NO = b.CHARGEPOLE_NO) ;”);

*/
/*

sqln = mysql_query(my_connection , “update M_VEH_CHARGE_REAL A set A.CHARGE_NO = “results[t]” where charge_no =”result[i]);

sqln = mysql_query(my_connection,”upate M_VEH_CHARGE_REAL C set C.BATTERYGROUP_MAX_TEMP= 0 , C.BMS_BUG = “”0″”, C.PASS_BUG = “”0″”, C.HARDWARE_BUG = “”0″”, C.OVER_CHARGE = “”0″” where chargepole_no = “result[i] );

*/

}

}
handler();

while(1)

;

}

mysql_free_result(results);

mysql_free_result(result);//释放结果集使用的内存。

mysql_close(my_connection);

return 0;

}
求转化 本人不懂occi 卸完了才发现数据库是oracle
求高手们帮帮忙

解决方案:35分
参考

demo\*.c

Program Name                              Features Illustrated

cdemo81.c                                 Using basic SQL processing with release 8 and later functionality.

cdemo82.c                                 Performing basic processing of user-defined objects.

cdemocor.c                                Using complex object retrieval (COR) to improve performance.

cdemodr1.c,cdemodr2.c,cdemodr3.c          Using INSERT/UPDATE/DELETE statements with RETURNING clause used with basic datatypes, LOBs and REFs.

cdemodsa.c                                Describing information about a table.

cdemodsc.c                                Describing information about an object type.

cdemofo.c                                 Registering and operating application failover callbacks.

cdemolb.c                                 Create and insert LOB data and then read, write, copy, append and trim the data.

cdemolb2.c                                Writing and reading of CLOB/BLOB columns with stream mode and callback functions.

cdemolbs.c                                Writing and reading to LOBs with the LOB buffering system.

cdemobj.c                                 Pinning and navigation of REF object.

cdemorid.c                                Using INSERT, UPDATE, DELETE statements and fetches to get multiple rowids in one round-trip.

cdemoses.c                                Using session switching and migration.

cdemothr.c                                Using the OCIThread package.

cdemosyev.c                               Registering predefined subscriptions and specifying a callback function to be invoked for client notifications (for more information about Advanced Queuing, see Oracle Streams Advanced Queuing User’s Guide and Reference).

ociaqdemo00.c,ociaqdemo01.c,ociaqdemo02.c Advanced queuing.

cdemodp.c,cdemodp_lip.c                   Loading data with the direct path load functions.

cdemdpco.c                                Loading a column object with the direct path load functions.

cdemdpno.c                                Loading a nested column object with the direct path load functions.

cdemdpin.c                                Loading derived type (inheritance) – direct path.

cdemdpit.c                                Loading an object table with inheritance – direct path.

cdemdpro.c                                Loading a reference with the direct path load functions.

cdemdpss.c                                Loading SQL strings with the direct path load functions.

cdemoucb.c,cdemoucbl.c                    Using static and dynamic user callbacks.

cdemoupk.c,cdemoup1.c,cdemoup2.c          Using dynamic user callbacks with multiple packages.

cdemodt.c                                 Datetime and interval example.

cdemosc.c                                 Scrollable cursor.

cdemol2l.c                                Accesses LOBs using the LONG API.

cdemoin1.c                                Inheritance demo which modifies an inherited type in a table and displays a record from the table.

cdemoin2.c                                Inheritance demo to do attribute substitutability.

cdemoin3.c                                Inheritance demo that describes an object, inherited types, object tables, and a sub-table.

cdemoanydata1.c                           Anydata demo. Inserts and selects rows to and from anydata table.

cdemoanydata2.c                           Anydata demo. Creates a type piecewise using OCITypeBeginCreate() and then describes the new type created.

cdemosp.c                                 Session pooling.

cdemocp.c                                 Connection pooling.

cdemocpproxy.c                            Connection pooling with proxy functionality.

cdemostc.c                                Statement caching.

cdemouni.c                                Program for OCI UTF16 API.

nchdemo1.c                                Shows nchar implicit conversion feature and codepoint feature.


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明linux c api连接数据库代码怎么变成occi方式代码
喜欢 (0)
[1034331897@qq.com]
分享 (0)