Skip to content

Commit 98aff92

Browse files
author
Daniel Schmidt
committed
Implemented getDeclaredType with documentation.
1 parent 01cf6f2 commit 98aff92

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/SQLiteCpp/Statement.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,22 @@ class Statement
643643
*/
644644
int getColumnIndex(const char* apName) const;
645645

646+
647+
/**
648+
* @brief Return the declared type of the specified result column for a SELECT statement.
649+
*
650+
* This is the type given at creation of the column and not the actual data type.
651+
* SQLite stores data types dynamically for each value and not per column.
652+
*
653+
* @param[in] aIndex Index of the column in the range [0, getColumnCount()).
654+
*
655+
* Throw an exception if the specified index is out of the [0, getColumnCount()) range
656+
* or if the current statement is not a SELECT statement.
657+
*/
658+
const char * getDeclaredType(const int aIndex) const;
659+
660+
661+
646662
////////////////////////////////////////////////////////////////////////////
647663

648664
/// Return the UTF-8 SQL Query.

src/Statement.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,20 @@ int Statement::getColumnIndex(const char* apName) const
296296
return (*iIndex).second;
297297
}
298298

299+
const char * Statement::getDeclaredType(const int aIndex) const
300+
{
301+
checkIndex(aIndex);
302+
const char * result = sqlite3_column_decltype(mStmtPtr, aIndex);
303+
if (!result)
304+
{
305+
throw SQLite::Exception("Could not determine declared column type.");
306+
}
307+
else
308+
{
309+
return result;
310+
}
311+
}
312+
299313
int Statement::getBindParameterCount() const noexcept
300314
{
301315
return sqlite3_bind_parameter_count(mStmtPtr);

0 commit comments

Comments
 (0)