/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-23 09:17:03 UTC
  • Revision ID: edam@waxworlds.org-20100723091703-3siqjj6eeux9hupz
- added NEWS
- added library checks to configure.ac
- added query::iterators
- remove dependency that rows have on querys (since querys have to be dependent on rows for boost::iterator_facade to work)
- rows now have the handle to the sqlite3 statement and know a count of their row number
- added convenience function tht can be used to detect presence of sqlite3cc in other packages
- updated test-main
- renamed all subdir.mk files to emake.mk

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        database &database,
30
30
        const std::string &sql )
31
31
        :
32
 
        basic_statement( database, sql )
 
32
        basic_statement( database, sql ),
 
33
        _next_row( 0 )
33
34
{
34
35
        assert( sqlite3_column_count( _handle ) > 0 );
35
36
}
38
39
sqlite::query::query(
39
40
        database &database )
40
41
        :
41
 
        basic_statement( database )
 
42
        basic_statement( database ),
 
43
        _next_row( 0 )
42
44
{
43
45
}
44
46
 
46
48
int sqlite::query::prepare(
47
49
        const std::string &sql )
48
50
{
 
51
        _next_row = 0;
49
52
        int error_code = basic_statement::prepare( sql );
50
53
        assert( error_code != SQLITE_OK || sqlite3_column_count( _handle ) > 0 );
51
54
        return error_code;
54
57
 
55
58
sqlite::row sqlite::query::step()
56
59
{
57
 
        int error_code = basic_statement::step();
58
 
        if( error_code == SQLITE_ROW )
59
 
                return row( *this );
60
 
        if( error_code == SQLITE_DONE )
61
 
                return row( *this, false );
62
 
        throw sqlite_error( error_code );
 
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
//      }
63
77
}
64
78
 
65
79
 
67
81
{
68
82
        return sqlite3_column_count( _handle );
69
83
}
 
84
 
 
85
 
 
86
const std::string sqlite::query::column_name(
 
87
        unsigned int index )
 
88
{
 
89
        assert( index <
 
90
                static_cast< unsigned int >( sqlite3_column_count( _handle ) ) );
 
91
        return sqlite3_column_name( _handle, index );
 
92
}
 
93
 
 
94
 
 
95
sqlite::query::iterator::iterator(
 
96
        sqlite::query &query,
 
97
        bool valid )
 
98
        :
 
99
        _query( query )
 
100
{
 
101
        if( valid )
 
102
                increment();
 
103
        else
 
104
                _valid = false;
 
105
}
 
106
 
 
107
 
 
108
sqlite::row sqlite::query::iterator::dereference() const
 
109
{
 
110
        return sqlite::row( _query._handle, _query._next_row++ );
 
111
}
 
112
 
 
113
 
 
114
void sqlite::query::iterator::increment()
 
115
{
 
116
        _valid = _query.step();
 
117
}
 
118
 
 
119
 
 
120
bool sqlite::query::iterator::equal(
 
121
        sqlite::query::iterator const &other )
 
122
        const
 
123
{
 
124
        return _valid == other._valid;
 
125
}
 
126
 
 
127
 
 
128
sqlite::query::iterator sqlite::query::begin()
 
129
{
 
130
        return sqlite::query::iterator( *this, true );
 
131
}
 
132
 
 
133
 
 
134
sqlite::query::iterator sqlite::query::end()
 
135
{
 
136
        return sqlite::query::iterator( *this, false );
 
137
}