/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to src/query.cc

  • Committer: edam
  • Date: 2010-07-29 06:39:13 UTC
  • Revision ID: edam@waxworlds.org-20100729063913-wvcvkogsa2alwkhr
- moved basic_statement::operator <<() back to basic_statement and just create another specialisation in command so that it can use sqlite::exec

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <sqlite3cc/query.h>
24
24
#include <sqlite3cc/row.h>
 
25
#include <sqlite3cc/database.h>
25
26
#include <assert.h>
26
27
 
27
28
 
49
50
        const std::string &sql )
50
51
{
51
52
        _next_row = 0;
52
 
        int error_code = basic_statement::prepare( sql );
53
 
        assert( error_code != SQLITE_OK || sqlite3_column_count( _handle ) > 0 );
54
 
        return error_code;
 
53
        int code = basic_statement::prepare( sql );
 
54
        assert( code != SQLITE_OK || sqlite3_column_count( _handle ) > 0 );
 
55
        return code;
55
56
}
56
57
 
57
58
 
58
59
sqlite::row sqlite::query::step()
59
60
{
60
 
//      sqlite3_mutex_enter( sqlite3_db_mutex( _database ) );
61
 
//      try {
62
 
                int error_code = basic_statement::step();
63
 
                if( error_code == SQLITE_ROW ) {
64
 
//                      sqlite3_mutex_leave( sqlite3_db_mutex( _database ) );
65
 
                        return row( _handle, _next_row++ );
66
 
                }
67
 
                if( error_code == SQLITE_DONE ) {
68
 
//                      sqlite3_mutex_leave( sqlite3_db_mutex( _database ) );
69
 
                        return row();
70
 
                }
71
 
                throw sqlite_error( error_code );
72
 
//      }
73
 
//      catch( ... ) {
74
 
//              sqlite3_mutex_leave( sqlite3_db_mutex( _database ) );
75
 
//              throw;
76
 
//      }
 
61
        database::database_mutex_guard lock( _database );
 
62
 
 
63
        int code = basic_statement::step();
 
64
        if( code == SQLITE_DONE ) return row();
 
65
        if( code == SQLITE_ROW ) return row( _handle, _next_row++ );
 
66
 
 
67
        throw sqlite_error( _database, code );
77
68
}
78
69
 
79
70
 
135
126
{
136
127
        return sqlite::query::iterator( *this, false );
137
128
}
 
129