本文整理汇总了C++中SQLGetDiagRec函数的典型用法代码示例。如果您正苦于以下问题:C++ SQLGetDiagRec函数的具体用法?C++ SQLGetDiagRec怎么用?C++ SQLGetDiagRec使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SQLGetDiagRec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strcpy
const char *COdbcConnection::ErrorString()
{
SQLCHAR state[6];
SQLINTEGER error;
SQLSMALLINT size = 512,len;
m_lasterrorString.resize((int)size);
SQLCHAR *pmsg = (SQLCHAR*)m_lasterrorString.data();
if(m_lastrsError.size())
{
strcpy((char*)pmsg,m_lastrsError.c_str());
pmsg+=m_lastrsError.size();
size-=(SQLSMALLINT)m_lastrsError.size();
m_lastrsError="";
}
if(m_hDbc)
{
for(int i=1; SQL_SUCCEEDED(SQLGetDiagRec(SQL_HANDLE_DBC, m_hDbc, i, state, &error, pmsg, size, &len)); i++)
{
size-=len;
pmsg+=len;
}
}
if(m_hEnv)
{
for(int i=1; SQL_SUCCEEDED(SQLGetDiagRec(SQL_HANDLE_ENV, m_hEnv, i, state, &error, pmsg, size, &len)); i++)
{
size-=len;
pmsg+=len;
}
}
m_lasterrorString.resize(512-size);
return m_lasterrorString.c_str();
}
示例2: odbc_Error
static void odbc_Error(SQLSMALLINT type, void *obj, t_eventlog_level level, const char *function)
{
SQLCHAR mState[6] = "\0";
long native = 0;
SQLSMALLINT mTextLen;
short i = 0;
while(SQLGetDiagRec(type, obj, ++i, NULL, NULL, NULL, 0, &mTextLen) != SQL_NO_DATA) {
SQLCHAR *mText = xcalloc(sizeof *mText, ++mTextLen);
SQLGetDiagRec(type, obj, i, mState, &native, mText, mTextLen, NULL);
eventlog(level, function, "ODBC Error: State %s, Native %i: %s", mState, native, mText);
xfree(mText);
}
}
示例3: HandleDiagnosticRecord
void HandleDiagnosticRecord (SQLHANDLE hHandle,
SQLSMALLINT hType,
RETCODE RetCode)
{
SQLSMALLINT iRec = 0;
SQLINTEGER iError;
char message[1000];
char state[SQL_SQLSTATE_SIZE+1];
if (RetCode == SQL_INVALID_HANDLE)
{
fprintf(stderr, "Invalid handle!\n");
return;
}
while (SQLGetDiagRec(hType,
hHandle,
++iRec,
state,
&iError,
message,
(SQLSMALLINT)(sizeof(message) / sizeof(WCHAR)),
(SQLSMALLINT *)NULL) == SQL_SUCCESS)
{
// Hide data truncated..
if (strncmp(state, "01004", 5))
{
fprintf(stderr, "[%5.5s] %s (%d)\n", state, message, iError);
}
}
}
示例4: odbc_report_error
void
odbc_report_error(const char *errmsg, int line, const char *file)
{
SQLSMALLINT handletype;
SQLHANDLE handle;
SQLRETURN ret;
SQLTCHAR sqlstate[6];
SQLTCHAR msg[256];
ODBC_BUF *odbc_buf = NULL;
if (odbc_stmt) {
handletype = SQL_HANDLE_STMT;
handle = odbc_stmt;
} else if (odbc_conn) {
handletype = SQL_HANDLE_DBC;
handle = odbc_conn;
} else {
handletype = SQL_HANDLE_ENV;
handle = odbc_env;
}
if (errmsg[0]) {
if (line)
fprintf(stderr, "%s:%d %s\n", file, line, errmsg);
else
fprintf(stderr, "%s\n", errmsg);
}
ret = SQLGetDiagRec(handletype, handle, 1, sqlstate, NULL, msg, ODBC_VECTOR_SIZE(msg), NULL);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
fprintf(stderr, "SQL error %s -- %s\n", C(sqlstate), C(msg));
odbc_disconnect();
ODBC_FREE();
exit(1);
}
示例5: prerr
static void
prerr(SQLSMALLINT tpe, SQLHANDLE hnd, const char *func, const char *pref)
{
SQLCHAR state[6];
SQLINTEGER errnr;
SQLCHAR msg[256];
SQLSMALLINT msglen;
switch (SQLGetDiagRec(tpe, hnd, 1, state, &errnr, msg, sizeof(msg), &msglen)) {
case SQL_SUCCESS_WITH_INFO:
if (msglen >= (signed int) sizeof(msg))
fprintf(stderr, "(message truncated)\n");
case SQL_SUCCESS:
fprintf(stderr, "%s: %s: SQLstate %s, Errnr %d, Message %s\n", func, pref, (char*)state, (int)errnr, (char*)msg);
break;
case SQL_INVALID_HANDLE:
fprintf(stderr, "%s: %s, invalid handle passed to error function\n", func, pref);
break;
case SQL_ERROR:
fprintf(stderr, "%s: %s, unexpected error from SQLGetDiagRec\n", func, pref);
break;
case SQL_NO_DATA:
fprintf(stderr, "%s: %s, no error message from driver\n", func, pref);
break;
default:
fprintf(stderr, "%s: %s, weird return value from SQLGetDiagRec\n", func, pref);
break;
}
}
示例6: getDiag
void getDiag(SQLSMALLINT type, SQLHANDLE handle, unsigned k, unsigned count)
{
char message[MAX_MESSAGE];
char state[6];
SQLINTEGER native;
SQLSMALLINT length = -1;
memset(message, 0, MAX_MESSAGE);
int ret = SQLGetDiagRec(type, handle, k, (SQLCHAR*)state,
&native, (SQLCHAR*)message, MAX_MESSAGE, &length);
if (ret == SQL_NO_DATA) {
ndbout << "No error diagnostics available" << endl;
return;
}
ndbout << message << endl;
if (k <= count && ret != SQL_SUCCESS)
ndbout_c("SQLGetDiagRec %d of %d: return %d != SQL_SUCCESS",
k, count, (int)ret);
if (k <= count && (SQLSMALLINT) strlen(message) != length)
ndbout_c("SQLGetDiagRec %d of %d: message length %d != %d",
k, count, strlen(message), length);
if (k > count && ret != SQL_NO_DATA)
ndbout_c("SQLGetDiagRec %d of %d: return %d != SQL_NO_DATA",
k, count, (int)ret);
}
示例7: odbc_report_error
void
odbc_report_error(const char *errmsg, int line, const char *file)
{
SQLSMALLINT handletype;
SQLHANDLE handle;
SQLRETURN ret;
unsigned char sqlstate[6];
unsigned char msg[256];
if (odbc_stmt) {
handletype = SQL_HANDLE_STMT;
handle = odbc_stmt;
} else if (odbc_conn) {
handletype = SQL_HANDLE_DBC;
handle = odbc_conn;
} else {
handletype = SQL_HANDLE_ENV;
handle = odbc_env;
}
if (errmsg[0]) {
if (line)
fprintf(stderr, "%s:%d %s\n", file, line, errmsg);
else
fprintf(stderr, "%s\n", errmsg);
}
ret = SQLGetDiagRec(handletype, handle, 1, sqlstate, NULL, msg, sizeof(msg), NULL);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
fprintf(stderr, "SQL error %s -- %s\n", sqlstate, msg);
odbc_disconnect();
exit(1);
}
示例8: run_statement
static void
run_statement(char *statement)
{
SQLRETURN ret;
char errmsg[500];
SQLSMALLINT textlen;
char sqlstate[20];
/*
* Skip empty lines. The server would just ignore them too, but might as
* well avoid the round-trip.
*/
if (statement[0] == '\0' || statement[0] == '\n')
return;
/* Skip comment lines too. */
if (statement[0] == '-' && statement[1] == '-')
return;
ret = SQLExecDirect(hstmt, (SQLCHAR *) statement, SQL_NTS);
if (!SQL_SUCCEEDED(ret))
{
printf("Statement failed: %s\n", statement);
ret = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, 1, sqlstate, NULL,
errmsg, sizeof(errmsg), &textlen);
if (ret == SQL_INVALID_HANDLE)
printf("Invalid handle\n");
else if (SQL_SUCCEEDED(ret))
printf("%s=%s\n", sqlstate, errmsg);
exit(1);
}
(void) SQLFreeStmt(hstmt, SQL_CLOSE);
}
示例9: connect_to_db
static void
connect_to_db(char *dsn)
{
SQLRETURN ret;
char errmsg[500];
SQLSMALLINT textlen;
char sqlstate[20];
SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
ret = SQLDriverConnect(conn, NULL, (SQLCHAR *) dsn, SQL_NTS, NULL, 0, NULL,
SQL_DRIVER_NOPROMPT);
if (!SQL_SUCCEEDED(ret))
{
printf("connection to %s failed\n", dsn);
ret = SQLGetDiagRec(SQL_HANDLE_DBC, conn, 1, sqlstate, NULL,
errmsg, sizeof(errmsg), &textlen);
if (ret == SQL_INVALID_HANDLE)
printf("Invalid handle\n");
else if (SQL_SUCCEEDED(ret))
printf("%s=%s\n", sqlstate, errmsg);
exit(1);
}
printf("connected to %s\n", dsn);
ret = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
if (!SQL_SUCCEEDED(ret))
{
printf("SQLAllocHandle failed\n");
exit(1);
}
}
示例10: SetError
bool SetError(int nResult, bool bFree = true) {
if (!myErrRes
&& !SQL_SUCCEEDED(nResult)) {
myErrBuf.Grow(1024);
myErrState.Grow(6);
SQLSMALLINT tlen = 0;
if (!SQLGetDiagRec(myType, myHandle, 1, (SQLCHAR*) myErrState.GetBuffer(), &myErrCode, (SQLCHAR*) (myErrBuf.GetBuffer())+8, myErrBuf.Length()-8, &tlen)) {
myErrBuf[0] = '(';
memcpy(myErrBuf+1, (const char *)myErrState, 5);
myErrBuf[6] = ')';
myErrBuf[7] = ' ';
myErrBuf.Grow(min(tlen+8,myErrBuf.Length()-8));
myErrRes = nResult;
} else {
myErrState = "00000";
myErrBuf = "(00000) No error.";
myErrRes = nResult;
}
if (bFree) {
SQLFreeHandle(myType, myHandle);
myHandle = 0;
}
return false;
}
return true;
}
示例11: __get_error
// Get an error of an ODBC handle
bool __get_error(SQLSMALLINT _handle_type, SQLHANDLE _handle, _tstring & _error_desc, _tstring & _status_code)
{
SQLTCHAR status_code[64], error_message[511];
SQLINTEGER i_native_error = 0;
SQLSMALLINT total_bytes = 0;
RETCODE rc;
// Ask for info
rc = SQLGetDiagRec(
_handle_type,
_handle,
1,
status_code,
&i_native_error,
error_message,
sizeof(error_message),
&total_bytes);
if (TIODBC_SUCCESS_CODE(rc))
{
_status_code = sqltchar2ybstring(status_code, "");
_error_desc = sqltchar2ybstring(error_message, "");
return true;
}
_error_desc = _T("Can't get error message");
_status_code = _T("UNKNOWN");
return false;
}
示例12: SQLAllocEnv
// Allocate environment handle, allocate connection handle,
// connect to data source, and allocate statement handle.
bool direxec::sqlconn(FILE* file)
{
logFile = file;
unsigned int timeout = 10; // seconds
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, &timeout, 0);
rc=SQLConnect(hdbc,chr_ds_name,SQL_NTS,NULL,0,NULL,0);
// Deallocate handles, display error message, and exit.
if (!MYSQLSUCCESS(rc))
{
SQLCHAR SqlState[6];
SQLINTEGER NativeError;
SQLSMALLINT MsgLen;
SQLGetDiagRec(SQL_HANDLE_DBC, hdbc, 1, SqlState, &NativeError, (unsigned char *) szData, 2048, &MsgLen);
SQLFreeEnv(henv);
SQLFreeConnect(hdbc);
fprintf(logFile, "! Error while connecting to database: %s\n", szData);
errorstate = TRUE;
return FALSE;
}
rc=SQLAllocStmt(hdbc,&hstmt);
errorstate = FALSE;
return TRUE;
}
示例13: extract_error
void extract_error(
char *fn,
SQLHANDLE handle,
SQLSMALLINT type)
{
SQLINTEGER i = 0;
SQLINTEGER native;
SQLCHAR state[ 7 ];
SQLCHAR text[256];
SQLSMALLINT len;
SQLRETURN ret;
fprintf(stderr,
"\n"
"The driver reported the following diagnostics whilst running "
"%s\n\n",
fn);
do
{
ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
sizeof(text), &len );
if (SQL_SUCCEEDED(ret))
printf("%s:%ld:%ld:%s\n", state, i, native, text);
}
while( ret == SQL_SUCCESS );
}
示例14: print_error_message
/**
* When SQLExecute returns either SQL_ERROR or SQL_SUCCESS_WITH_INFO,
* an associated SQLSTATE value can be obtained by calling SQLGetDiagRec
* with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle.
*/
static SQLINTEGER
print_error_message(SQLSMALLINT hType, SQLHANDLE handle) {
int i;
SQLINTEGER ndiag=0;
SQLRETURN ret;
SQLCHAR state[6];
SQLINTEGER error, maxerror=0;
SQLCHAR text[1024];
SQLSMALLINT len;
ret = SQLGetDiagField(hType, handle, 0, SQL_DIAG_NUMBER, &ndiag, sizeof(ndiag), NULL);
assert(ret == SQL_SUCCESS);
for(i=1; i <= ndiag; i++) {
memset(text, '\0', sizeof(text));
ret = SQLGetDiagRec(hType, handle, i, state, &error, text, sizeof(text), &len);
if (ret == SQL_SUCCESS && error == 0) {
fprintf(stdout, "\"%s\"\n", text);
continue;
}
fprintf(stderr, "%s: error %d: %s: %s\n", options.appname, (int)error, state, text);
assert(ret == SQL_SUCCESS);
if (error > maxerror)
maxerror = error;
}
return maxerror;
}
示例15: db__driver_execute_immediate
int db__driver_execute_immediate(dbString * sql)
{
char *s, msg[OD_MSG];
cursor *c;
SQLRETURN ret;
SQLINTEGER err;
s = db_get_string(sql);
/* allocate cursor */
c = alloc_cursor();
if (c == NULL)
return DB_FAILED;
ret = SQLExecDirect(c->stmt, s, SQL_NTS);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_STMT, c->stmt, 1, NULL, &err, msg,
sizeof(msg), NULL);
db_d_append_error("SQLExecDirect():\n%s\n%s (%d)\n", s, msg,
(int)err);
db_d_report_error();
return DB_FAILED;
}
free_cursor(c);
return DB_OK;
}