void main()
{
OCIEnvCreate(&myenvhp, OCI_THREADED|OCI_OBJECT, (dvoid *)0,
0, 0, 0, (size_t) 0, (dvoid **)0);
OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&mysrvhp,
OCI_HTYPE_SERVER, 0, (dvoid **) 0);
OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&myerrhp,
OCI_HTYPE_ERROR, 0, (dvoid **) 0);
if (OCIServerAttach (mysrvhp, myerrhp, (text *)"orcl",
strlen ("orcl"), OCI_DEFAULT) == OCI_SUCCESS)
MessageBox("1!\n");
else
{
MessageBox("2!\n");
//return -1;
}
OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&mysvchp,
OCI_HTYPE_SVCCTX, 0, (dvoid **) 0);
OCIAttrSet ((dvoid *)mysvchp, OCI_HTYPE_SVCCTX,
(dvoid *)mysrvhp, (ub4) 0, OCI_ATTR_SERVER, myerrhp);
OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&myusrhp,
OCI_HTYPE_SESSION, 0, (dvoid **) 0);
OCIAttrSet ((dvoid *)myusrhp, OCI_HTYPE_SESSION,
(dvoid *)"lsqsql", (ub4)strlen("lsqsql"),
OCI_ATTR_USERNAME, myerrhp);
OCIAttrSet ((dvoid *)myusrhp, OCI_HTYPE_SESSION,
(dvoid *)"123456", (ub4)strlen("123456"),
OCI_ATTR_PASSWORD, myerrhp);
if (OCISessionBegin ((OCISvcCtx *) mysvchp, myerrhp, myusrhp,
OCI_CRED_RDBMS, OCI_DEFAULT) == OCI_SUCCESS)
{
MessageBox("3!\n");
}
else
{
MessageBox("4\n");
// return -1;
}
text* create1 = (text*)"create table georaster_table(georid number primary key, type varchar2(32), georaster mdsys.sdo_georaster)";
sb4 status = 0;
OCIAttrSet ( (dvoid *)mysvchp, OCI_HTYPE_SVCCTX,
(dvoid *)myusrhp, (ub4) 0, OCI_ATTR_SESSION, myerrhp);
int tt=CheckErr(myerrhp, OCIHandleAlloc(myenvhp, (void**)&stmthp, OCI_HTYPE_STMT, 0, 0));
int cc=CheckErr(myerrhp, OCIStmtPrepare(stmthp, myerrhp, create1, strlen((char*)create1),
OCI_NTV_SYNTAX, OCI_DEFAULT));
status = OCIStmtExecute(mysvchp, stmthp, myerrhp, 1, 0, NULL, NULL,
OCI_DEFAULT|OCI_COMMIT_ON_SUCCESS|OCI_BATCH_ERRORS);
if (status && status != OCI_SUCCESS_WITH_INFO)
{
OCIHandleFree((dvoid*)myenvhp, OCI_HTYPE_ENV);
return ;
}
}
在执行status=OCIStmtExecute(mysvchp, stmthp, myerrhp, 1, 0, NULL, NULL,
OCI_DEFAULT|OCI_COMMIT_ON_SUCCESS|OCI_BATCH_ERRORS);这句代码之前都没有任何问题,此时status=-1,请教各位大虾,这是什么问题?谢谢了!
------解决方案--------------------
改成:status=OCIStmtExecute(mysvchp, stmthp, myerrhp, 1, 0, NULL, NULL,
OCI_DEFAULT)呢?
如果status等于-1,把error信息打出来就知道是什么错了。
给一个类似的出错信息伪码:
switch (status)
{
case OCI_SUCCESS:
break;
case OCI_SUCCESS_WITH_INFO:
break;
case OCI_NEED_DATA:
throw DBException(file, line, "Error - OCI_NEED_DATA\n");
break;
case OCI_NO_DATA:
throw DBException(file, line, "Error - OCI_NODATA\n");
break;
case OCI_ERROR:
{
char buf[1024];
(void) o->OCIErrorGet_f((dvoid *)errhp, (ub4) 1, (text *) NULL, &errcode,
(text*)buf, (ub4) sizeof(buf), OCI_HTYPE_ERROR);
throw DBException(file, line, buf);
break;
}
case OCI_INVALID_HANDLE:
throw DBException(file, line, "Error - OCI_INVALID_HANDLE\n");
break;
case OCI_STILL_EXECUTING:
throw DBException(file, line, "Error - OCI_STILL_EXECUTE\n");
break;
case OCI_CONTINUE:
throw DBException(file, line, "Error - OCI_CONTINUE\n");
break;
default:
break;
}