@@ -25,90 +25,90 @@ const int BLOB = SQLITE_BLOB;
2525const int Null = SQLITE_NULL;
2626
2727
28- // Encapsulation of a Column in a row of the result pointed by the prepared Statement.
29- Column::Column (const StatementPtr::TRawStatementPtr& aStmtPtr, int aIndex) :
30- mStmtPtr (aStmtPtr),
31- mIndex (aIndex)
32- {
33- if (!aStmtPtr)
34- {
35- throw SQLite::Exception (" Statement was destroyed" );
36- }
37- }
38-
3928// Return the named assigned to this result column (potentially aliased)
4029const char * Column::getName () const noexcept
4130{
42- return sqlite3_column_name (mStmtPtr . get (), mIndex );
31+ return sqlite3_column_name (mStatementPtr -> getStatement (), mIndex );
4332}
4433
4534#ifdef SQLITE_ENABLE_COLUMN_METADATA
4635// Return the name of the table column that is the origin of this result column
4736const char * Column::getOriginName () const noexcept
4837{
49- return sqlite3_column_origin_name (mStmtPtr . get (), mIndex );
38+ return sqlite3_column_origin_name (mStatementPtr -> getStatement (), mIndex );
5039}
5140#endif
5241
5342// Return the integer value of the column specified by its index starting at 0
54- int32_t Column::getInt () const noexcept
43+ int32_t Column::getInt () const
5544{
56- return sqlite3_column_int (mStmtPtr . get (), mIndex );
45+ return sqlite3_column_int (getStatement (), mIndex );
5746}
5847
5948// Return the unsigned integer value of the column specified by its index starting at 0
60- uint32_t Column::getUInt () const noexcept
49+ uint32_t Column::getUInt () const
6150{
6251 return static_cast <unsigned >(getInt64 ());
6352}
6453
6554// Return the 64bits integer value of the column specified by its index starting at 0
66- int64_t Column::getInt64 () const noexcept
55+ int64_t Column::getInt64 () const
6756{
68- return sqlite3_column_int64 (mStmtPtr . get (), mIndex );
57+ return sqlite3_column_int64 (getStatement (), mIndex );
6958}
7059
7160// Return the double value of the column specified by its index starting at 0
72- double Column::getDouble () const noexcept
61+ double Column::getDouble () const
7362{
74- return sqlite3_column_double (mStmtPtr . get (), mIndex );
63+ return sqlite3_column_double (getStatement (), mIndex );
7564}
7665
7766// Return a pointer to the text value (NULL terminated string) of the column specified by its index starting at 0
78- const char * Column::getText (const char * apDefaultValue /* = "" */ ) const noexcept
67+ const char * Column::getText (const char * apDefaultValue /* = "" */ ) const
7968{
80- auto pText = reinterpret_cast <const char *>(sqlite3_column_text (mStmtPtr . get (), mIndex ));
69+ auto pText = reinterpret_cast <const char *>(sqlite3_column_text (getStatement (), mIndex ));
8170 return (pText ? pText : apDefaultValue);
8271}
8372
8473// Return a pointer to the blob value (*not* NULL terminated) of the column specified by its index starting at 0
85- const void * Column::getBlob () const noexcept
74+ const void * Column::getBlob () const
8675{
87- return sqlite3_column_blob (mStmtPtr . get (), mIndex );
76+ return sqlite3_column_blob (getStatement (), mIndex );
8877}
8978
9079// Return a std::string to a TEXT or BLOB column
9180std::string Column::getString () const
9281{
82+ auto statement = getStatement ();
83+
9384 // Note: using sqlite3_column_blob and not sqlite3_column_text
9485 // - no need for sqlite3_column_text to add a \0 on the end, as we're getting the bytes length directly
95- auto data = static_cast <const char *>(sqlite3_column_blob (mStmtPtr . get () , mIndex ));
86+ auto data = static_cast <const char *>(sqlite3_column_blob (statement , mIndex ));
9687
9788 // SQLite docs: "The safest policy is to invoke… sqlite3_column_blob() followed by sqlite3_column_bytes()"
9889 // Note: std::string is ok to pass nullptr as first arg, if length is 0
99- return std::string (data, sqlite3_column_bytes (mStmtPtr . get () , mIndex ));
90+ return std::string (data, sqlite3_column_bytes (statement , mIndex ));
10091}
10192
10293// Return the type of the value of the column
10394int Column::getType () const noexcept
10495{
105- return sqlite3_column_type (mStmtPtr . get (), mIndex );
96+ return sqlite3_column_type (mStatementPtr -> getStatement (), mIndex );
10697}
10798
10899// Return the number of bytes used by the text value of the column
109- int Column::getBytes () const noexcept
100+ int Column::getBytes () const
110101{
111- return sqlite3_column_bytes (mStmtPtr .get (), mIndex );
102+ return sqlite3_column_bytes (getStatement (), mIndex );
103+ }
104+
105+ sqlite3_stmt* Column::getStatement () const
106+ {
107+ if (mStatementPtr ->mCurrentStep != mRowIndex )
108+ {
109+ throw SQLite::Exception (" Column is used after SQLite Statement Object has been changed" );
110+ }
111+ return mStatementPtr ->getStatement ();
112112}
113113
114114// Standard std::ostream inserter
0 commit comments