mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Added inline cast operators to the Column::getXxx() appropriate functions
+ added a standard std::ostream inserter
This commit is contained in:
parent
4288cb511e
commit
716a50be78
@ -53,3 +53,11 @@ const char * Column::getText(void) const // throw(SQLite::Exception)
|
|||||||
|
|
||||||
|
|
||||||
}; // namespace SQLite
|
}; // namespace SQLite
|
||||||
|
|
||||||
|
|
||||||
|
// Standard std::ostream inserter
|
||||||
|
std::ostream& operator<<(std::ostream &stream, SQLite::Column const& column)
|
||||||
|
{
|
||||||
|
stream << column.getText();
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
@ -33,25 +33,44 @@ public:
|
|||||||
* @brief Compile and register the SQL query for the provided SQLite Database Connection
|
* @brief Compile and register the SQL query for the provided SQLite Database Connection
|
||||||
*/
|
*/
|
||||||
explicit Column(sqlite3* apSQLite, sqlite3_stmt* apStmt, int aIndex) throw(); // nothrow
|
explicit Column(sqlite3* apSQLite, sqlite3_stmt* apStmt, int aIndex) throw(); // nothrow
|
||||||
|
/// Basic destructor
|
||||||
virtual ~Column(void) throw(); // nothrow
|
virtual ~Column(void) throw(); // nothrow
|
||||||
|
|
||||||
/**
|
/// Return the integer value of the column.
|
||||||
* @brief Return the integer value of the column
|
|
||||||
*/
|
|
||||||
int getInt (void) const; // throw(SQLite::Exception);
|
int getInt (void) const; // throw(SQLite::Exception);
|
||||||
/**
|
// Return the 64bits integer value of the column.
|
||||||
* @brief Return the 64bits integer value of the column
|
|
||||||
*/
|
|
||||||
sqlite3_int64 getInt64 (void) const; // throw(SQLite::Exception);
|
sqlite3_int64 getInt64 (void) const; // throw(SQLite::Exception);
|
||||||
/**
|
// Return the double (64bits float) value of the column.
|
||||||
* @brief Return the double (64bits float) value of the column
|
|
||||||
*/
|
|
||||||
double getDouble(void) const; // throw(SQLite::Exception);
|
double getDouble(void) const; // throw(SQLite::Exception);
|
||||||
/**
|
// Return the text value (NULL terminated string) of the column.
|
||||||
* @brief Return the text value (NULL terminated string) of the column
|
|
||||||
*/
|
|
||||||
const char* getText (void) const; // throw(SQLite::Exception);
|
const char* getText (void) const; // throw(SQLite::Exception);
|
||||||
|
|
||||||
|
/// Inline cast operator to int
|
||||||
|
inline operator const int() const
|
||||||
|
{
|
||||||
|
return getInt();
|
||||||
|
}
|
||||||
|
/// Inline cast operator to 64bits integer
|
||||||
|
inline operator const sqlite3_int64() const
|
||||||
|
{
|
||||||
|
return getInt64();
|
||||||
|
}
|
||||||
|
/// Inline cast operator to double
|
||||||
|
inline operator const double() const
|
||||||
|
{
|
||||||
|
return getDouble();
|
||||||
|
}
|
||||||
|
/// Inline cast operator to char*
|
||||||
|
inline operator const char*() const
|
||||||
|
{
|
||||||
|
return getText();
|
||||||
|
}
|
||||||
|
/// Inline cast operator to std::string
|
||||||
|
inline operator const std::string() const
|
||||||
|
{
|
||||||
|
return getText();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Column is copyable, but copy should not be used elsewhere than in return form getColumn
|
// Column is copyable, but copy should not be used elsewhere than in return form getColumn
|
||||||
Column(void);
|
Column(void);
|
||||||
@ -65,3 +84,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
}; // namespace SQLite
|
}; // namespace SQLite
|
||||||
|
|
||||||
|
|
||||||
|
/// Standard std::ostream inserter
|
||||||
|
std::ostream& operator<<(std::ostream &stream, SQLite::Column const& column);
|
||||||
|
@ -17,7 +17,13 @@ int main (void)
|
|||||||
|
|
||||||
while (query.executeStep())
|
while (query.executeStep())
|
||||||
{
|
{
|
||||||
std::cout << "row : (" << query.getColumn(0).getInt() << ", " << query.getColumn(1).getText() << ", " << query.getColumn(2).getInt() << ")\n";
|
int id = query.getColumn(0); // = query.getColumn(0).getInt()
|
||||||
|
//const char* pvalue = query.getColumn(1); // = query.getColumn(1).getText()
|
||||||
|
std::string value = query.getColumn(1); // = query.getColumn(1).getText()
|
||||||
|
int size = query.getColumn(2); // = query.getColumn(2).getInt()
|
||||||
|
|
||||||
|
std::cout << "row : (" << id << ", " << value << ", " << size << ")\n";
|
||||||
|
std::cout << "row : (" << query.getColumn(0) << ", " << query.getColumn(1) << ", " << query.getColumn(2) << ")\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user