아래에 이어 delete 문까지 안되는걸로 봐서 뭔가 빠트린듯 하여 소스 올립니다~
bind를 사용하면 cci_execute가 0으로 리턴 되네요~ 흠냐;;
그리고 bind를 사용 안하는 코드로 Delete 한 후에는 csql(큐브리드 메니저)에서는 분명히 없는대,
샘플 예제로 select 문을 수행하면 값이 있습니다. 두둥!! o_O
server, service 둘다 종료해서 다시 시작해도 똑같습니다.
도대체 무슨경우지;; OTL
====================================================================
// 안됨
int req, res;
char *delete_sql = "DELETE FROM TBL_USER WHERE AND ID=?";
char buf[CUBRID_BUF_SIZE+1];
T_CCI_ERROR error;
if ((req = cci_prepare( nConHandle, delete_sql, 0, &error)) < 0) {
... }
if ((res = cci_bind_param(req, 1, CCI_A_TYPE_STR, (void *)"inimax", CCI_U_TYPE_STRING, (char)NULL)) < 0) {
... }
if ((res = cci_execute(req, 0, 0, &error)) < 0) {
... }
printf("%dn", res);
if (cci_end_tran( nConHandle, CCI_TRAN_COMMIT, &error) < 0) {
...
}
======================================================================
//잘됨
char *delete_sql = "DELETE FROM TBL_USER WHERE ID='inimax'";
char buf[CUBRID_BUF_SIZE+1];
T_CCI_ERROR error;
// 질의 컴파일을 수행한다.
if ((req = cci_prepare( nConHandle, delete_sql, 0, &error)) < 0) {
... }
// 질의를 수행한다.
if ((res = cci_execute(req, 0, 0, &error)) < 0) {
... }
printf("%dn", res);
// 에러없이 정상 처리되었으므로 커밋 처리한다.
if (cci_end_tran( nConHandle, CCI_TRAN_COMMIT, &error) < 0) {
... }
저도 비슷하게 cci API 를 이용하여 시험을 해보았는데..
문제가 없이 잘 동작하는 것 같습니다.
혹시 위에 첨부해주신 예제를 보면 char *delete_sql = "DELETE FROM TBL_USER WHERE AND ID=?";
WHERE AND 오타 때문이 아닐까요 ^^
제가 해본 내용을 아래에 첨부해봅니다.
$ cat cci.c
#define BUF_SIZE 512
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cas_cci.h"
int port;
insert_data(int con)
{
int req, res;
// char *sql = "insert into nation1(code,name) values(?, ?)";
char *sql = "delete from nation1 where code = ?";
char *code = "kor";
// char *name = "...";
char buf[BUF_SIZE+1];
T_CCI_ERROR error;
if ((req = cci_prepare(con, sql, 0, &error)) < 0) {
printf("prepare error[%d] %sn SQL: %sn", error.err_code, error.err_msg, sql);
cci_end_tran(con, CCI_TRAN_ROLLBACK, &error);
return 0;
}
if ((res = cci_bind_param(req, 1, CCI_A_TYPE_STR, (void *)"kor", CCI_U_TYPE_STRING, (char)NULL)) < 0) {
cci_get_err_msg (res, buf, BUF_SIZE);
printf("bind error 1 [%d] %sn", res, buf);
cci_end_tran(con, CCI_TRAN_ROLLBACK, &error);
return 0;
}
if ((res = cci_execute(req, 0, 0, &error)) < 0) {
printf("prepare error[%d] %sn SQL: %sn", error.err_code, error.err_msg, sql);
cci_end_tran(con, CCI_TRAN_ROLLBACK, &error);
return 0;
}
if (cci_end_tran(con, CCI_TRAN_COMMIT, &error) < 0) {
printf("COMMIT ERROR [%d] %sn", error.err_code, error.err_msg);
return 0;
}
return 1;
}
main(int argc, char **argv)
{
int con = 0;
char oid[39];
int res;
char buf[BUF_SIZE+1];
T_CCI_ERROR error;
port = 33000;
if ((con = cci_connect("localhost", port, "demodb", "PUBLIC", "")) < 0) {
printf("localhost demodb connection errorn");
exit(-1);
}
if (insert_data(con) == 0) {
printf("Error input datan");
cci_disconnect(con, &error);
exit(-1);
}
cci_disconnect(con, &error);
}
$ gcc -o cci cci.c -I$CUBRID/include -L$CUBRID/lib -lcascci
$ csql demodb -c "insert into nation1(code,name) values('kor','x')"
$ csql demodb -c "select * from nation1"
=== <Result of SELECT Command in Line 1> ===
code name continent capital
========================================================================================
'kor' 'x' NULL NULL
$ ./cci
$ csql demodb -c "select * from nation1"
=== <Result of SELECT Command in Line 1> ===
There are no results.
$ cubrid_rel
CUBRID 2008 R3.1