mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 17:56:13 -04:00
Merge pull request #45 from HighSparrow/master
Fix issue: Column by name #23
This commit is contained in:
commit
dae5388ece
@ -295,6 +295,33 @@ public:
|
|||||||
*/
|
*/
|
||||||
Column getColumn(const int aIndex);
|
Column getColumn(const int aIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return a copy of the column data specified by its column name
|
||||||
|
*
|
||||||
|
* Can be used to access the data of the current row of result when applicable,
|
||||||
|
* while the executeStep() method returns true.
|
||||||
|
*
|
||||||
|
* Throw an exception if there is no row to return a Column from :
|
||||||
|
* - before any executeStep() call
|
||||||
|
* - after the last executeStep() returned false
|
||||||
|
* - after a reset() call
|
||||||
|
*
|
||||||
|
* Throw an exception if the specified index is out of the [0, getColumnCount()) range.
|
||||||
|
*
|
||||||
|
* @param[in] aName Name of the column, starting at index 0
|
||||||
|
*
|
||||||
|
* @note This method is no more const, starting in v0.5,
|
||||||
|
* which reflects the fact that the returned Column object will
|
||||||
|
* share the ownership of the underlying sqlite3_stmt.
|
||||||
|
*
|
||||||
|
* @warning The resulting Column object must not be memorized "as-is".
|
||||||
|
* Is is only a wrapper around the current result row, so it is only valid
|
||||||
|
* while the row from the Statement remains valid, that is only until next executeStep() call.
|
||||||
|
* Thus, you should instead extract immediately its data (getInt(), getText()...)
|
||||||
|
* and use or copy this data for any later usage.
|
||||||
|
*/
|
||||||
|
Column getColumn(const char* aName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Test if the column value is NULL
|
* @brief Test if the column value is NULL
|
||||||
*
|
*
|
||||||
|
@ -256,6 +256,33 @@ Column Statement::getColumn(const int aIndex)
|
|||||||
return Column(mStmtPtr, aIndex);
|
return Column(mStmtPtr, aIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a copy of the column data specified by its column name starting at 0
|
||||||
|
// (use the Column copy-constructor)
|
||||||
|
Column Statement::getColumn(const char* aName)
|
||||||
|
{
|
||||||
|
int aIndex = -1;
|
||||||
|
|
||||||
|
if (false == mbOk)
|
||||||
|
{
|
||||||
|
throw SQLite::Exception("No row to get a column from");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < mColumnCount; i++) {
|
||||||
|
if (sqlite3_column_name(mStmtPtr, i) == aName)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((aIndex < 0) || (aIndex >= mColumnCount)) {
|
||||||
|
throw SQLite::Exception("Column index out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Share the Statement Object handle with the new Column created
|
||||||
|
return Column(mStmtPtr, aIndex);
|
||||||
|
}
|
||||||
|
|
||||||
// Test if the column is NULL
|
// Test if the column is NULL
|
||||||
bool Statement::isColumnNull(const int aIndex) const
|
bool Statement::isColumnNull(const int aIndex) const
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user