Exemple #1
0
int lem::sqlite_select_int( struct sqlite3* hdb, const lem::FString & Select )
{
    LEM_CHECKIT_Z( hdb!=NULL );
    LEM_CHECKIT_Z( !Select.empty() );

    int retval=-1;

    sqlite3_stmt *stmt=NULL;
    const char *dummy;
    int res = sqlite3_prepare_v2( hdb, Select.c_str(), Select.length(), &stmt, &dummy );
    if( res==SQLITE_OK )
    {
        res = sqlite3_step( stmt );
        if( res == SQLITE_ROW )
        {
            try
            {
                retval = sqlite3_column_int(stmt,0);
            }
            catch(...)
            {
            }
        }

        sqlite3_finalize(stmt);
    }
    else
    {
        lem::MemFormatter msg;
        msg.printf( "SQLite error: can not execute query %s, message=%us", Select.c_str(), lem::sqlite_errmsg(hdb).c_str() );
        throw E_BaseException( msg.string() );
    }

    return retval;
}
int StorageConnection_SQLITE::SelectInt( const lem::FString &sql, int default_value )
{
 int retval=default_value;

 sqlite3_stmt *stmt=NULL;
 const char *dummy;
 int res = sqlite3_prepare_v2( hdb, sql.c_str(), sql.length(), &stmt, &dummy );
 if( res==SQLITE_OK )
  {
   res = sqlite3_step( stmt );
   if( res == SQLITE_ROW )
    {
     try
      {
       retval = sqlite3_column_int(stmt,0);
      }
     catch(...)
      {
      }
    }

   sqlite3_finalize(stmt);
  }
 else
  {
   lem::MemFormatter msg;
   msg.printf( "SQLite error: can not execute query %s, message=%us", sql.c_str(), lem::sqlite_errmsg(hdb).c_str() );
   throw lem::E_BaseException( msg.string() );
  }

 return retval;
}