Esempio n. 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;
}
void NGramsStorage_SQLITE::SelectFStrings( const lem::FString &Select, lem::Collect<lem::FString> &list )
{
 LEM_CHECKIT_Z( !Select.empty() );

 sqlite3_stmt *stmt=NULL;
 int res = sqlite3_prepare_v2( hdb, Select.c_str(), -1, &stmt, NULL );
 if( res==SQLITE_OK )
  {
   while( sqlite3_step( stmt ) == SQLITE_ROW )
    {
     lem::FString s = lem::sqlite_column_fstring( stmt, 0 );
     list.push_back(s);
    } 

   sqlite3_finalize(stmt);
  }

 return;
}
int NGramsStorage_SQLITE::SelectInt( const lem::FString &Select, int def )
{
 LEM_CHECKIT_Z( !Select.empty() );

 int retval=def;

 sqlite3_stmt *stmt=NULL;
 int res = sqlite3_prepare_v2( hdb, Select.c_str(), -1, &stmt, NULL );
 if( res==SQLITE_OK )
  {
   if( sqlite3_step( stmt ) == SQLITE_ROW )
    {
     retval = sqlite3_column_int(stmt,0);
    } 

   sqlite3_finalize(stmt);
  }

 return retval;
}
void NGramsStorage_SQLITE::ExecuteSql( const lem::FString &sql, bool check )
{
 LEM_CHECKIT_Z( !sql.empty() );
 ExecuteSql(sql.c_str(),check);
 return;
}