Adding the method getBytes to the Column object, returning the size in bytes of the text value.

This commit is contained in:
Sébastien Rombauts 2013-03-08 21:24:38 +01:00
parent bc5b64d4a3
commit dc4802edd5
4 changed files with 20 additions and 3 deletions

View File

@ -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() ?

View File

@ -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)
{

View File

@ -52,7 +52,17 @@ 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

View File

@ -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