Beispiel #1
0
bool DbNote::existCategory(Category & category)
{
    sqlite3_stmt *statement;
    string stmnt = "select count(*) from KatTable where KatDesc like ? or KatKey = ?";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Select-Statement failed in existCategory()");
        return false;
    }
    req = sqlite3_bind_text(statement, 1, category.getDesc().c_str(), category.getDesc().size(), 0 );
    req = sqlite3_bind_int(statement, 2, category.getKatKey());
    if (req != SQLITE_OK)
    {
        throw SQLError("Binding Date into select statement failed");
        return false;
    }
    req = sqlite3_step(statement);

    int catCount = static_cast<int>(sqlite3_column_int(statement, 0));

    sqlite3_finalize(statement);
    sqlite3_close(db);
    if (catCount > 0)
        return true;
    return false;


}
Beispiel #2
0
int
ODBC_Errors (char *where)
{
  unsigned char buf[250];
  unsigned char sqlstate[15];

  /*
   *  Get statement errors
   */
  while (SQLError (henv, hdbc, hstmt, sqlstate, NULL,
	buf, sizeof(buf), NULL) == SQL_SUCCESS)
    {
      fprintf (stdout, "%s ||%s, SQLSTATE=%s\n", where, buf, sqlstate);
    }

  /*
   *  Get connection errors
   */
  while (SQLError (henv, hdbc, SQL_NULL_HSTMT, sqlstate, NULL,
	buf, sizeof(buf), NULL) == SQL_SUCCESS)
    {
      fprintf (stdout, "%s ||%s, SQLSTATE=%s\n", where, buf, sqlstate);
    }

  /*
   *  Get environmental errors
   */
  while (SQLError (henv, SQL_NULL_HDBC, SQL_NULL_HSTMT, sqlstate, NULL,
	buf, sizeof(buf), NULL) == SQL_SUCCESS)
    {
      fprintf (stdout, "%s ||%s, SQLSTATE=%s\n", where, buf, sqlstate);
    }

  return -1;
}
Beispiel #3
0
/*-----------------------------------------------------------------------------*/
int PrintErrorMsg(struct Cursor *cur)
{
  UCHAR FAR *szsqlstate;
  SDWORD FAR *pfnativeerror;
  UCHAR FAR *szerrormsg;
  SWORD cberrormsgmax;
  SWORD FAR *pcberrormsg;
  RETCODE rc;

  szsqlstate=(UCHAR FAR *)malloc(sizeof(UCHAR FAR)*10);
  pfnativeerror=(SDWORD FAR *)malloc(sizeof(SDWORD FAR));
  szerrormsg=(UCHAR FAR *)malloc(sizeof(UCHAR FAR)*SQL_MAX_MESSAGE_LENGTH);
  pcberrormsg=(SWORD FAR *)malloc(sizeof(SWORD FAR));
  cberrormsgmax=SQL_MAX_MESSAGE_LENGTH-1;
  if (cur != NULL)
    rc = SQLError(SQL_NULL_HENV, cur->hdbc, cur->hstmt, szsqlstate,
		  pfnativeerror, szerrormsg,cberrormsgmax,pcberrormsg);
  else
    rc = SQLError(SQL_NULL_HENV, NULL, SQL_NULL_HSTMT, szsqlstate,
		  pfnativeerror, szerrormsg,cberrormsgmax,pcberrormsg);
  if ((rc == SQL_SUCCESS) || (rc == SQL_SUCCESS_WITH_INFO)) { 
    printf("ODBC SYSCALL ERROR (CODE %s): %s\n", szsqlstate, szerrormsg);
  }
  free(szsqlstate);
  free(pfnativeerror);
  free(szerrormsg);
  free(pcberrormsg);
  return 1;
}
Beispiel #4
0
bool DbNote::deleteRow(string sqlStmnt)
{
    sqlite3_stmt *statement;
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, sqlStmnt.c_str(), sqlStmnt.length(),
                                 &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Delete-Statement failed");
        return false;
    }
    req = sqlite3_step(statement);
    if (req != SQLITE_DONE)
    {
        throw SQLError("execute of delete statement failed");
        return false;
    }
    sqlite3_finalize(statement);
    sqlite3_close(db);
    return true;
}
Beispiel #5
0
int DumpODBCLog( SQLHENV hEnv, SQLHDBC hDbc, SQLHSTMT hStmt )
{
	SQLCHAR		szError[501];
	SQLCHAR		szSqlState[10];
    SQLINTEGER  nNativeError;
    SQLSMALLINT	nErrorMsg;

	if ( hStmt )
	{
		while ( SQLError( hEnv, hDbc, hStmt, szSqlState, &nNativeError, szError, 500, &nErrorMsg ) == SQL_SUCCESS )
		{
			printf( "%s\n", szError );
		}
	}

	if ( hDbc )
	{
		while ( SQLError( hEnv, hDbc, 0, szSqlState, &nNativeError, szError, 500, &nErrorMsg ) == SQL_SUCCESS )
		{
			printf( "%s\n", szError );
		}
	}

	if ( hEnv )
	{
		while ( SQLError( hEnv, 0, 0, szSqlState, &nNativeError, szError, 500, &nErrorMsg ) == SQL_SUCCESS )
		{
			printf( "%s\n", szError );
		}
	}

	return 1;
}
Beispiel #6
0
bool DbNote::existNote(Note & note)
{
    sqlite3_stmt *statement;
    string stmnt = "select count(*) from NoteTable where NoteKey = ?";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing select-Statement failed");
        return false;
    }
    req = sqlite3_bind_int(statement, 1, note.getNoteKey());

    if (req != SQLITE_OK)
    {
        throw SQLError("Binding Date into select statement failed");
        return false;
    }
    req = sqlite3_step(statement);

    int noteCount = static_cast<int>(sqlite3_column_int(statement, 0));

    sqlite3_finalize(statement);
    sqlite3_close(db);
    if (noteCount > 0)
        return true;
    return false;
}
Beispiel #7
0
/* Pass NULL to use system's error message. */
static void
gsql_save_error_message (Database *db, char *msg)
{
  unsigned char buf[256];
  unsigned char sqlstate[15];
  char odbc_error_variable[128];
  BPRINTF_BUFFER *err;

  /* Get statement errors */
  while (SQLError (db->henv, db->hdbc, db->hstmt, sqlstate, NULL,
      buf, sizeof(buf), NULL) == SQL_SUCCESS)
    {
      sprintf (odbc_error_variable, "odbc::odbc-error-message[%d]",
	       odbc_error_index);
      odbc_error_index++;

      err = bprintf_create_buffer ();
      bprintf (err, "HSTMT: SQLSTATE=%s %s\n", sqlstate, buf);
      pagefunc_set_variable (odbc_error_variable, err->buffer);
      page_debug ("ODBC: %s", err->buffer);
      bprintf_free_buffer (err);
    }

  /* Get connection errors */
  while (SQLError (db->henv, db->hdbc, SQL_NULL_HSTMT, sqlstate, NULL,
      buf, sizeof(buf), NULL) == SQL_SUCCESS)
    {
      sprintf (odbc_error_variable, "odbc::odbc-error-message[%d]",
	       odbc_error_index);
      odbc_error_index++;
      err = bprintf_create_buffer ();
      bprintf (err, "Connection: SQLSTATE=%s %s\n", sqlstate, buf);
      pagefunc_set_variable (odbc_error_variable,  err->buffer);
      page_debug ("ODBC: %s", err->buffer);
      bprintf_free_buffer (err);
    }

  /* Get environmental errors */
  while (SQLError (db->henv, SQL_NULL_HDBC, SQL_NULL_HSTMT, sqlstate, NULL,
      buf, sizeof(buf), NULL) == SQL_SUCCESS)
    {
      sprintf (odbc_error_variable, "odbc::odbc-error-message[%d]",
	       odbc_error_index);
      odbc_error_index++;
      err = bprintf_create_buffer ();
      bprintf (err, "Environment: SQLSTATE=%s %s\n", sqlstate, buf);
      pagefunc_set_variable (odbc_error_variable, err->buffer);
      page_debug ("ODBC: %s", err->buffer);
      bprintf_free_buffer (err);
    }

  if (msg != GSQL_DEFAULT_ERRMSG)
    {
      sprintf (odbc_error_variable, "odbc::odbc-error-message[%d]",
	       odbc_error_index);
      odbc_error_index++;
      page_debug ("ODBC: %s", msg);
      pagefunc_set_variable (odbc_error_variable, msg);
    }
}
Beispiel #8
0
BOOL errchk(char* s)
{
   UCHAR szSqlState[256];
   SDWORD pfNativeError;
   UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
   SWORD pcbErrorMsg;
   char buf[SQL_MAX_MESSAGE_LENGTH + 40];

   switch (g_RC)
   {
      case SQL_SUCCESS:
//         messout("success");
         break;
      case SQL_SUCCESS_WITH_INFO:
         if (SQL_NO_DATA_FOUND != SQLError(g_hEnv, g_hDBC, g_hSTMT,
               szSqlState, &pfNativeError, szErrorMsg,
               SQL_MAX_MESSAGE_LENGTH-1, &pcbErrorMsg))
            messout((char*)szErrorMsg);
         else
            messout("SQL success with info, no additional information available");
         break;
      case SQL_NO_DATA_FOUND:
         messout("no data found"); break;
      case SQL_ERROR:
         strcpy(buf, s);
         strcat(buf, "\n");
         if (SQL_NO_DATA_FOUND != SQLError(g_hEnv, g_hDBC, g_hSTMT,
               szSqlState, &pfNativeError, szErrorMsg,
               SQL_MAX_MESSAGE_LENGTH-1, &pcbErrorMsg))
         {
            strcat(buf, szSqlState);
            strcat(buf, " ");
            strcat(buf, (char*)szErrorMsg);
         }
         else
            strcat(buf, "SQL error, no additional information available");
         messout(buf);
         break;
      case SQL_INVALID_HANDLE:
         messout("invalid handle"); break;
      case SQL_STILL_EXECUTING:
         messout("still executing"); break;
      case SQL_NEED_DATA:
         messout("need data"); break;
      default:
         messout("something strange"); break;
   }
   return TRUE;
}
void ODBC_error (			/* Obtain ODBC Error */
		HENV henv,			/* ODBC Environment */
		HDBC hdbc,			/* ODBC Connection Handle */
		HSTMT hstmt)			/* ODBC SQL Handle */
{
	SQLTCHAR	sqlstate[10];
	SQLTCHAR	errmsg[SQL_MAX_MESSAGE_LENGTH];
	SDWORD	nativeerr;
	SWORD	actualmsglen;
	RETCODE	rc;

loop:  	rc = SQLError((SQLHENV)henv, (SQLHDBC)hdbc, (SQLHSTMT)hstmt,
			sqlstate, &nativeerr, errmsg,
			SQL_MAX_MESSAGE_LENGTH - 1, &actualmsglen);

	if (rc == SQL_ERROR) {
		printf ("SQLError failed!\n");
		return;
	}

	if (rc != SQL_NO_DATA_FOUND) {
		printf ("SQLSTATE = %s\n",sqlstate);
		printf ("NATIVE ERROR = %d\n",nativeerr);
		errmsg[actualmsglen] = '\0';
		printf ("MSG = %s\n\n",errmsg);
		goto loop;
	}
}
Beispiel #10
0
int DBWorker::GenerateDefaultObjective(int idproblem)
{
    try {
        sql::PreparedStatement *PrepStmt;
        sql::PreparedStatement *PrepStmt2;
        sql::ResultSet *res;

        PrepStmt = con->prepareStatement("SELECT idobjectives FROM objectives WHERE idproblems=? and default_obj=1");
        PrepStmt->setInt(1, idproblem);
        res = PrepStmt->executeQuery();
        delete PrepStmt;

        if(res->next())
        {
            int ret = res->getInt(1);
            delete res;
            return ret;
        }
        delete res;

        PrepStmt2 = con->prepareStatement("INSERT INTO objectives(idproblems,direction,default_obj) VALUES(?,'min',1)");
        PrepStmt2->setInt(1, idproblem);
        PrepStmt2->execute();
        delete PrepStmt2;

        return GenerateDefaultObjective(idproblem);
    }
    catch (sql::SQLException &e) {
        SQLError(e);
    }
}
Beispiel #11
0
void DBWorker::RunBatchOnMultipeModels(int idbatches, vector<string> modelfiles, bool mip)
{
    try {
        sql::PreparedStatement *PrepStmt;
        sql::ResultSet *res;

        PrepStmt = con->prepareStatement(
                       "select bat_order, idobjectives from batch_elem where idbatches=? order by bat_order"
                   );
        PrepStmt->setInt(1,idbatches);
        res = PrepStmt->executeQuery();
        delete PrepStmt;

        int idobjective;
        while(res->next())
        {
            idobjective = res->getInt(2);
            for (vector<string>::iterator it = modelfiles.begin() ; it != modelfiles.end(); ++it)
            {
                DoRun(idobjective,it->c_str(),mip);
            }
        }
        delete res;

    }
    catch (sql::SQLException &e) {
        SQLError(e);
    }
}
Beispiel #12
0
void DBWorker::RunBatch(int idbatches, char* modelfile, bool mip) {
    try {
        sql::PreparedStatement *PrepStmt;
        sql::ResultSet *res;

        PrepStmt = con->prepareStatement(
                       "select bat_order, idobjectives from batch_elem where idbatches=? order by bat_order"
                   );
        PrepStmt->setInt(1,idbatches);
        res = PrepStmt->executeQuery();
        delete PrepStmt;

        int idobjective;
        while(res->next())
        {
            idobjective = res->getInt(2);
            DoRun(idobjective,modelfile,mip);
        }
        delete res;

    }
    catch (sql::SQLException &e) {
        SQLError(e);
    }
}
Beispiel #13
0
int odbc_error(ClipMachine* cm,SQLLocale* loc,SQLHENV henv,SQLHDBC hdbc,SQLHSTMT hstmt,int line,const char* er_){
	char state[6];
	SQLINTEGER native;
	char error[MAX_ERROR_MESSAGE_LEN+1];
	SQLSMALLINT errlen;
	char err[MAX_ERROR_MESSAGE_LEN+1];
	int u;
	char *r,*c,*e;

	u = SQLError(henv,hdbc,hstmt,state,&native,error,MAX_ERROR_MESSAGE_LEN,&errlen);
	while((r = strchr(error,';'))) *r = ' ';
	while((r = strchr(error,'\n'))) *r = ';';
	while((r = strchr(error,'\r'))) *r = ' ';
	if(native)
		snprintf(err,MAX_ERROR_MESSAGE_LEN,";%s; SQLSTATE: %s : Native error %d;%s;",
			er_,state,(int)native,error);
	else
		snprintf(err,MAX_ERROR_MESSAGE_LEN,";%s; SQLSTATE: %s;%s;",
			er_,state,error);
	if(loc){
		c = err;
		e = err+strlen(err);
		for(;c<e;c++)
			if(*c&0x80)
				*c = loc->read[*c&0x7f];
	}
	_clip_trap_err(cm, 0, 0, 0, __FILE__, line, err);
	return -1;
}
/*************************************************************************
 *
 *	Function: sql_error
 *
 *	Purpose: database specific error. Returns error associated with
 *               connection
 *
 *************************************************************************/
static const char *sql_error(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config) {
    SQLCHAR state[256];
    SQLCHAR error[256];
    SQLINTEGER errornum = 0;
    SQLSMALLINT length = 255;
    static char result[1024];	/* NOT thread-safe! */

    rlm_sql_unixodbc_sock *unixodbc_sock = handle->conn;

    error[0] = state[0] = '\0';

    SQLError(
	unixodbc_sock->env_handle,
	unixodbc_sock->dbc_handle,
	unixodbc_sock->stmt_handle,
	state,
	&errornum,
	error,
	256,
	&length);

    sprintf(result, "%s %s", state, error);
    result[sizeof(result) - 1] = '\0'; /* catch idiot thread issues */
    return result;
}
Beispiel #15
0
void DBWorker::PrintResultsToStreamByObjective(ostream& out, int idobjective)
{
    try {
        sql::PreparedStatement *PrepStmt;
        sql::ResultSet *res;


        PrepStmt = con->prepareStatement(
                       "SELECT idruns, runtype FROM theproblem.runs where idobjectives=? order by runtype desc, idruns;"
                   );
        PrepStmt->setInt(1,idobjective);
        res = PrepStmt->executeQuery();
        delete PrepStmt;

        while(res->next())
        {
            PrintResultToStream(out,res->getInt(1), strcmp(res->getString(2).c_str(),"mip"));
            out << endl;
        }

        delete res;

    }
    catch (sql::SQLException &e) {
        SQLError(e);
    }
}
bool CRecordSet::GetErrorMessage(char *sOutError, const int iErrBufSz)
{
	SQLCHAR     sSQLState[20];
	SQLINTEGER  iOutNativeErr;
	SQLSMALLINT iOutErrorMsgSz;
	return SQL_SUCCEEDED(SQLError(NULL, NULL, hSTMT, sSQLState, &iOutNativeErr, (SQLCHAR *)sOutError, iErrBufSz, &iOutErrorMsgSz));
}
Beispiel #17
0
/*
  call SQLError to get error information and log it
 */
int
logPsgError(int level, HENV henv, HDBC hdbc, HSTMT hstmt, int dbType)
{
   SQLCHAR         sqlstate[ SQL_SQLSTATE_SIZE + 10];
   SQLINTEGER sqlcode;
   SQLSMALLINT length;
   int errorVal=-2;
   while (SQLError(henv, hdbc, hstmt, sqlstate, &sqlcode, psgErrorMsg,
		   SQL_MAX_MESSAGE_LENGTH + 1, &length) == SQL_SUCCESS) {
      if (dbType == DB_TYPE_MYSQL) {
	 if (strcmp((char *)sqlstate,"23000") == 0 && 
	     strstr((char *)psgErrorMsg, "Duplicate entry")) {
	    errorVal = CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
	 }
      }
      else {
	 if (strstr((char *)psgErrorMsg, "duplicate key")) {
	    errorVal = CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
	 }
      }
      rodsLog(level,"SQLSTATE: %s", sqlstate);
      rodsLog(level,"SQLCODE: %ld", sqlcode);
      rodsLog(level,"SQL Error message: %s", psgErrorMsg);
   }
   return(errorVal);
}
Beispiel #18
0
/* ------------------------------------------------------------- */
static int check_error (PJXSQL pSQL)
{
  SQLSMALLINT length;
  ULONG l;

  SQLHENV       henv  = SQL_NULL_HENV;
  SQLHDBC       hdbc  = SQL_NULL_HDBC;
  SQLHSTMT      hstmt = pSQL ? pSQL->hstmt : SQL_NULL_HSTMT;
  UCHAR         sqlState[5];
  LONG          sqlCode;
  UCHAR         sqlMsgDta[SQL_MAX_MESSAGE_LENGTH + 1];
  PUCHAR        psqlState  = sqlState;
  PLONG         psqlCode   = &sqlCode;
  PUCHAR        psqlMsgDta = sqlMsgDta;

  if ( pConnection) {
     henv  = pConnection->henv;
     hdbc  = pConnection->hdbc;
     psqlState  = pConnection->sqlState;
     psqlCode   = &pConnection->sqlCode;
     psqlMsgDta = pConnection->sqlMsgDta;
  }

  while ( SQLError(henv, hdbc, hstmt, psqlState, psqlCode, psqlMsgDta, sizeof(sqlMsgDta), &length) == SQL_SUCCESS) {
     substr ( jxMessage , psqlMsgDta , length);
  };

  if (pSQL) {
     jx_sqlClose (&pSQL); // Free the data
  }

  jxError = true;

  return;
}
Beispiel #19
0
void DBWorker::PrintResultsByBatch(int idbatches)
{
    try {
        sql::PreparedStatement *PrepStmt;
        sql::ResultSet *res;


        PrepStmt = con->prepareStatement(
                       "SELECT batch_elem.idobjectives, CONCAT(CONCAT_WS('-',CONCAT('b',idbatches),bat_order,name),'.csv') filename FROM batch_elem, objectives, problems where batch_elem.idobjectives=objectives.idobjectives and objectives.idproblems=problems.idproblems and batch_elem.idbatches=? order by bat_order;"
                   );
        PrepStmt->setInt(1,idbatches);
        res = PrepStmt->executeQuery();
        delete PrepStmt;

        ofstream out;
        while(res->next())
        {
            out.open(res->getString(2).c_str());
            if (out)
                PrintResultsToStreamByObjective(out,res->getInt(1));
            out.close();
        }

        delete res;

    }
    catch (sql::SQLException &e) {
        SQLError(e);
    }
}
Beispiel #20
0
void
odbc_error ()
{
  SWORD len;
  SQLError (hstmt || hdbc ? SQL_NULL_HENV : henv, hstmt ? SQL_NULL_HDBC : hdbc, hstmt, (UCHAR *) state, NULL,
      (UCHAR *) &message, sizeof (message), &len);
  printf ("\n*** Error %s: %s\n", state, message);
  fflush (stdout);
}
Beispiel #21
0
void CODBC::SaveSQLError()
{
	unsigned char szSQLSTATE[10];
	SDWORD nErr;
	SWORD cbmsg;

	// fetch the last SQL error
	SQLError(0, 0, hstmt, szSQLSTATE, &nErr, (unsigned char*) lastError, sizeof(lastError), &cbmsg);
}
Beispiel #22
0
// return error message 
char* direxec::error_msg(void)
{
   unsigned char szSQLSTATE[10];
   SDWORD nErr;
   SWORD cbmsg;

   if (SQLError(0, 0, hstmt, szSQLSTATE, &nErr, (unsigned char*) msg, sizeof(msg), &cbmsg) == SQL_SUCCESS)
      return msg;
   else
	  return (char *) "";
}
Beispiel #23
0
int DBWorker::GenerateBathch(char* batch_name)
{
    int idbatches=0;
    try {
        sql::PreparedStatement *PrepStmt;
        sql::ResultSet *res;

        PrepStmt = con->prepareStatement(
                       "INSERT INTO batches(name) VALUES(?)"
                   );
        PrepStmt->setString(1,batch_name);
        PrepStmt->execute();

        PrepStmt = con->prepareStatement(
                       "SELECT LAST_INSERT_ID()"
                   );
        res = PrepStmt->executeQuery();
        delete PrepStmt;
        res->next();
        idbatches = res->getInt(1);
        delete res;

        PrepStmt = con->prepareStatement(
                       "INSERT INTO batch_elem(idbatches,bat_order,idobjectives) VALUES(?,?,?)"
                   );
        PrepStmt->setInt(1,idbatches);

        int i=1;
        CMyProblem P(0,0);
        for(int n=21; n<=30; n++)
        {
            while (i<=(n-20)*6)
            {
                char buff[256];
                sprintf(buff, "b%d-%d_%d",idbatches,n,i);
                //P.GenerateRandomProblem(n,3,buff);
                P.GenerateRandomProblemWNC(n,3+((n-20)*6-i-1)/3,buff);
                int idproblems = P.WriteToDB();
                int idobjectives = GenerateDefaultObjective(idproblems);
                PrepStmt->setInt(2,i);
                PrepStmt->setInt(3,idobjectives);
                PrepStmt->execute();
                i++;
            }
        }


        delete PrepStmt;
    }
    catch (sql::SQLException &e) {
        SQLError(e);
    }
    return idbatches;
}
Beispiel #24
0
bool DbNote::openDB()
{
    if (sqlite3_open(file.c_str(), &db) != SQLITE_OK)
    {
        const char * error = sqlite3_errmsg(db);
        sqlite3_close(db);
        throw SQLError(error);
        return false;
    }
    return true;
}
Beispiel #25
0
char* CSQLEx::GetLastError()
{
	char szError[1024];

    SQLCHAR     szState[20];
	SQLINTEGER  iNativeError;
	SQLSMALLINT iOutErrorSize;

	SQLError(this->m_SQLEnvironment,this->m_SQLConnection,this->m_STMT,szState,&iNativeError,(SQLCHAR*)szError,sizeof(szError),&iOutErrorSize);

    return &szError[0];
}
Beispiel #26
0
void
print_error (HSTMT e1, HSTMT e2, HSTMT e3)
{
  SWORD len;
  char state[10];
  char message[1000];
  SQLError (e1, e2, e3, (UCHAR *) state, NULL,
      (UCHAR *) &message, sizeof (message), &len);
  printf ("\n*** Error %s: %s\n", state, message);
  if (0 == strcmp (state, "08S01"))
    exit (-1);
}
Beispiel #27
0
void print_error (HSTMT e1, HSTMT e2, HSTMT e3)
{
  int len;
  char state [10];
  char message [1000];
  while (SQL_SUCCESS ==
	 SQLError (e1, e2, e3, (UCHAR *) state, NULL,
		   (UCHAR *) & message, sizeof (message),
		   (SWORD *) & len))
    if (!messages_off)
      printf ("*** Error %s: %s\n", state, message);
}
Beispiel #28
0
void CQuery::LogError()
{
	UCHAR szMsg[SQL_MAX_MESSAGE_LENGTH] = {0};
	UCHAR szState[SQL_SQLSTATE_SIZE+1] = {0};
	SQLSMALLINT nLen;
	SQLINTEGER nError;
	int nIndex = 0;

	SQLRETURN ret = SQLError(m_hEnv, m_hDbc, m_hStmt, szState, &nError, szMsg, SQL_MAX_MESSAGE_LENGTH-1, &nLen );

	Log( Error, "Error %i SQLSTATE:%s error:%s", nError, (char*)szState,(char*)szMsg );
}
Beispiel #29
0
int DbNote::getNextNoteKey( void )
{
    sqlite3_stmt *statement;
    string stmnt = "SELECT seq FROM SQLITE_SEQUENCE where name = \"NoteTable\"";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Select-Statement failed in getNextNoteKey()");
        return false;
    }
    req = sqlite3_step(statement);
    int noteKey = static_cast<int>(sqlite3_column_int(statement, 0));
    sqlite3_finalize(statement);
    sqlite3_close(db);
    return ( !noteKey ) ? 1 : noteKey;
}
Beispiel #30
0
bool DbNote::createDB()
{
    sqlite3_stmt *statement;
    string stmnt = "CREATE TABLE KatTable(	KatKey INTEGER PRIMARY KEY\
										autoincrement,KatDesc TEXT);";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Select-Statement failed in existCategory()");
        return false;
    }
    req = sqlite3_step(statement);
    sqlite3_finalize(statement);

    stmnt = "CREATE TABLE NoteTable( NoteKey INTEGER PRIMARY KEY autoincrement,\
						date TEXT,\
						NoteText TEXT,\
						NoteTitle TEXT,\
						KatKey INTEGER,\
						NoteRef INTEGER,\
						FOREIGN KEY (KatKey) REFERENCES KatTable(KatKey));";
    req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Select-Statement failed in existCategory()");
        return false;
    }
    req = sqlite3_step(statement);
    sqlite3_finalize(statement);
    sqlite3_close(db);
    Category c;
    c.setKatDesc("notice (default)");
    insertTable(c);
    return true;
}