mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-03 09:16:06 -04:00
Added a new Column::getName() method inspired by NachoSoto
- Close #8 pull request to pull-request #8
This commit is contained in:
parent
05a37fd64c
commit
cc17771d2a
@ -18,7 +18,7 @@
|
||||
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1034724773." name="/" resourcePath="">
|
||||
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.898681687" name="Linux GCC" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.exe.debug" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
|
||||
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.25715897" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
|
||||
<builder buildPath="${ProjDirPath}" id="cdt.managedbuild.target.gnu.builder.exe.debug.1103730408" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
|
||||
<builder buildPath="${ProjDirPath}/build" id="cdt.managedbuild.target.gnu.builder.exe.debug.1103730408" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.836634439" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||
<tool command="g++" id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1817615032" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
|
||||
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.750523151" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
|
||||
|
@ -32,6 +32,7 @@ Version 0.5.0 - March 9 2013
|
||||
Version 0.5.1 - April 7 2013
|
||||
Added Collumn::getName()
|
||||
|
||||
TODO 0.6.0 - ?? 2013
|
||||
Version 0.6.0 - November 22 2013
|
||||
Renamed Collumn::getName() to Collumn::getOriginName()
|
||||
Added a new Collumn::getName()
|
||||
|
||||
|
@ -93,7 +93,7 @@ int main (void)
|
||||
std::cout << "execAndGet=" << value.c_str() << std::endl;
|
||||
|
||||
// Compile a SQL query, containing one parameter (index 1)
|
||||
SQLite::Statement query(db, "SELECT * FROM test WHERE weight > ?");
|
||||
SQLite::Statement query(db, "SELECT id as test_id, value as test_val, weight as test_weight FROM test WHERE weight > ?");
|
||||
std::cout << "SQLite statement '" << query.getQuery().c_str() << "' compiled (" << query.getColumnCount () << " columns in the result)\n";
|
||||
// Bind the integer value 2 to the first parameter of the SQL query
|
||||
query.bind(1, 2);
|
||||
@ -109,20 +109,25 @@ int main (void)
|
||||
int bytes = query.getColumn(1).getBytes();
|
||||
double weight = query.getColumn(2); // = query.getColumn(2).getInt()
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
static bool bFirst = true;
|
||||
if (bFirst)
|
||||
{
|
||||
// Show how to get the name of the table column from which this particular result column come from.
|
||||
// Show how to get the aliased names of the result columns.
|
||||
std::string name0 = query.getColumn(0).getName();
|
||||
std::string name1 = query.getColumn(1).getName();
|
||||
std::string name2 = query.getColumn(2).getName();
|
||||
std::cout << "aliased result [\"" << name0.c_str() << "\", \"" << name1.c_str() << "\", \"" << name2.c_str() << "\"]\n";
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
// Show how to get origin names of the table columns from which thoses result columns come from.
|
||||
// Requires the SQLITE_ENABLE_COLUMN_METADATA preprocessor macro to be
|
||||
// also defined at compile times of the SQLite library itself.
|
||||
std::string name0 = query.getColumn(0).getOriginName();
|
||||
std::string name1 = query.getColumn(1).getOriginName();
|
||||
std::string name2 = query.getColumn(2).getOriginName();
|
||||
std::cout << "table 'test' [\"" << name0.c_str() << "\", \"" << name1.c_str() << "\", \"" << name2.c_str() << "\"]\n";
|
||||
name0 = query.getColumn(0).getOriginName();
|
||||
name1 = query.getColumn(1).getOriginName();
|
||||
name2 = query.getColumn(2).getOriginName();
|
||||
std::cout << "origin table 'test' [\"" << name0.c_str() << "\", \"" << name1.c_str() << "\", \"" << name2.c_str() << "\"]\n";
|
||||
#endif
|
||||
bFirst = false;
|
||||
}
|
||||
#endif
|
||||
std::cout << "row (" << id << ", \"" << value2.c_str() << "\" " << bytes << " bytes, " << weight << ")\n";
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,12 @@ Column::~Column(void) throw() // nothrow
|
||||
// the finalization will be done by the destructor of the last shared pointer
|
||||
}
|
||||
|
||||
// Return the named assigned to this result column (potentially aliased)
|
||||
const char * Column::getName(void) const throw() // nothrow
|
||||
{
|
||||
return sqlite3_column_name(mStmtPtr, mIndex);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
// Return the name of the table column that is the origin of this result column
|
||||
const char * Column::getOriginName(void) const throw() // nothrow
|
||||
|
@ -51,7 +51,12 @@ public:
|
||||
// default copy constructor and assignment operator are perfectly suited :
|
||||
// they copy the Statement::Ptr which in turn increments the reference counter.
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
/**
|
||||
* @brief Return a pointer to the named assigned to a result column (potentially aliased)
|
||||
*/
|
||||
const char* getName (void) const throw(); // nothrow
|
||||
|
||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||
/**
|
||||
* @brief Return a pointer to the table column name that is the origin of this result column
|
||||
*
|
||||
|
@ -38,5 +38,5 @@
|
||||
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
|
||||
* numbers used in [SQLITECPP_VERSION].
|
||||
*/
|
||||
#define SQLITECPP_VERSION "0.5.1"
|
||||
#define SQLITECPP_VERSION_NUMBER 0005001
|
||||
#define SQLITECPP_VERSION "0.6.0"
|
||||
#define SQLITECPP_VERSION_NUMBER 0006000
|
||||
|
Loading…
x
Reference in New Issue
Block a user