From dc4802edd5f45144e3995586544de01580217d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Fri, 8 Mar 2013 21:24:38 +0100 Subject: [PATCH] Adding the method getBytes to the Column object, returning the size in bytes of the text value. --- TODO.txt | 1 - src/SQLiteC++/Column.cpp | 7 +++++++ src/SQLiteC++/Column.h | 12 +++++++++++- src/example1/main.cpp | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index d7821ff..7bfb429 100644 --- a/TODO.txt +++ b/TODO.txt @@ -7,7 +7,6 @@ Publish the Doxygen Documentation in the Github Pages (gh-pages branch) Missing features in v0.4.0: - **Blob** => make an example/test with image stored in a row -- getBytes - getColumnType + isText + isInt + isDouble... - getColumnByName ? std::map getRow() ? diff --git a/src/SQLiteC++/Column.cpp b/src/SQLiteC++/Column.cpp index 148307c..1934e96 100644 --- a/src/SQLiteC++/Column.cpp +++ b/src/SQLiteC++/Column.cpp @@ -51,6 +51,13 @@ const char* Column::getText(void) const throw() // nothrow return (const char*)sqlite3_column_text(mStmtPtr, mIndex); } +// Return the number of bytes used by the text value of the column +int Column::getBytes(void) const throw() // nothrow +{ + return sqlite3_column_bytes(mStmtPtr, mIndex); +} + + // Standard std::ostream inserter std::ostream& operator<<(std::ostream& aStream, const Column& aColumn) { diff --git a/src/SQLiteC++/Column.h b/src/SQLiteC++/Column.h index 5cea6d2..10c2319 100644 --- a/src/SQLiteC++/Column.h +++ b/src/SQLiteC++/Column.h @@ -52,8 +52,18 @@ public: /// thus you must copy it before using it beyond its scope (to a std::string for instance). const char* getText (void) const throw(); // TODO const void* getBlob (void) const throw(); -// TODO int getBytes (void) const throw(); + /** + * @brief Return the number of bytes used by the text value of the column + * + * Return either : + * - size in bytes (not in characters) of the string returned by getText() without the '\0' terminator + * - size in bytes of the string representation of the numerical value (integer or double) + * - TODO size in bytes of the binary blob returned by getBlob() + * - 0 for a NULL value + */ + int getBytes(void) const throw(); + /// Inline cast operator to int inline operator int() const { diff --git a/src/example1/main.cpp b/src/example1/main.cpp index a78efdf..b83f02e 100644 --- a/src/example1/main.cpp +++ b/src/example1/main.cpp @@ -87,9 +87,10 @@ int main (void) int id = query.getColumn(0); // = query.getColumn(0).getInt() //const char* pvalue = query.getColumn(1); // = query.getColumn(1).getText() std::string value2 = query.getColumn(1); // = query.getColumn(1).getText() + int bytes = query.getColumn(1).getBytes(); int size = query.getColumn(2); // = query.getColumn(2).getInt() - std::cout << "row : (" << id << ", " << value2.c_str() << ", " << size << ")\n"; + std::cout << "row : (" << id << ", " << value2.c_str() << ", " << bytes << ", " << size << ")\n"; } // Reset the query to use it again