Skip to content

Commit cc17771

Browse files
committed
Added a new Column::getName() method inspired by NachoSoto
- Close SRombauts#8 pull request to pull-request SRombauts#8
1 parent 05a37fd commit cc17771

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

.cproject

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1034724773." name="/" resourcePath="">
1919
<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">
2020
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.25715897" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
21-
<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"/>
21+
<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"/>
2222
<tool id="cdt.managedbuild.tool.gnu.archiver.base.836634439" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
2323
<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">
2424
<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"/>

CHANGELOG.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Version 0.5.0 - March 9 2013
3232
Version 0.5.1 - April 7 2013
3333
Added Collumn::getName()
3434

35-
TODO 0.6.0 - ?? 2013
35+
Version 0.6.0 - November 22 2013
3636
Renamed Collumn::getName() to Collumn::getOriginName()
37+
Added a new Collumn::getName()
3738

examples/example1/main.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int main (void)
9393
std::cout << "execAndGet=" << value.c_str() << std::endl;
9494

9595
// Compile a SQL query, containing one parameter (index 1)
96-
SQLite::Statement query(db, "SELECT * FROM test WHERE weight > ?");
96+
SQLite::Statement query(db, "SELECT id as test_id, value as test_val, weight as test_weight FROM test WHERE weight > ?");
9797
std::cout << "SQLite statement '" << query.getQuery().c_str() << "' compiled (" << query.getColumnCount () << " columns in the result)\n";
9898
// Bind the integer value 2 to the first parameter of the SQL query
9999
query.bind(1, 2);
@@ -109,20 +109,25 @@ int main (void)
109109
int bytes = query.getColumn(1).getBytes();
110110
double weight = query.getColumn(2); // = query.getColumn(2).getInt()
111111

112-
#ifdef SQLITE_ENABLE_COLUMN_METADATA
113112
static bool bFirst = true;
114113
if (bFirst)
115114
{
116-
// Show how to get the name of the table column from which this particular result column come from.
115+
// Show how to get the aliased names of the result columns.
116+
std::string name0 = query.getColumn(0).getName();
117+
std::string name1 = query.getColumn(1).getName();
118+
std::string name2 = query.getColumn(2).getName();
119+
std::cout << "aliased result [\"" << name0.c_str() << "\", \"" << name1.c_str() << "\", \"" << name2.c_str() << "\"]\n";
120+
#ifdef SQLITE_ENABLE_COLUMN_METADATA
121+
// Show how to get origin names of the table columns from which thoses result columns come from.
117122
// Requires the SQLITE_ENABLE_COLUMN_METADATA preprocessor macro to be
118123
// also defined at compile times of the SQLite library itself.
119-
std::string name0 = query.getColumn(0).getOriginName();
120-
std::string name1 = query.getColumn(1).getOriginName();
121-
std::string name2 = query.getColumn(2).getOriginName();
122-
std::cout << "table 'test' [\"" << name0.c_str() << "\", \"" << name1.c_str() << "\", \"" << name2.c_str() << "\"]\n";
124+
name0 = query.getColumn(0).getOriginName();
125+
name1 = query.getColumn(1).getOriginName();
126+
name2 = query.getColumn(2).getOriginName();
127+
std::cout << "origin table 'test' [\"" << name0.c_str() << "\", \"" << name1.c_str() << "\", \"" << name2.c_str() << "\"]\n";
128+
#endif
123129
bFirst = false;
124130
}
125-
#endif
126131
std::cout << "row (" << id << ", \"" << value2.c_str() << "\" " << bytes << " bytes, " << weight << ")\n";
127132
}
128133

src/Column.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Column::~Column(void) throw() // nothrow
3030
// the finalization will be done by the destructor of the last shared pointer
3131
}
3232

33+
// Return the named assigned to this result column (potentially aliased)
34+
const char * Column::getName(void) const throw() // nothrow
35+
{
36+
return sqlite3_column_name(mStmtPtr, mIndex);
37+
}
38+
3339
#ifdef SQLITE_ENABLE_COLUMN_METADATA
3440
// Return the name of the table column that is the origin of this result column
3541
const char * Column::getOriginName(void) const throw() // nothrow

src/Column.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ class Column
5151
// default copy constructor and assignment operator are perfectly suited :
5252
// they copy the Statement::Ptr which in turn increments the reference counter.
5353

54-
#ifdef SQLITE_ENABLE_COLUMN_METADATA
54+
/**
55+
* @brief Return a pointer to the named assigned to a result column (potentially aliased)
56+
*/
57+
const char* getName (void) const throw(); // nothrow
58+
59+
#ifdef SQLITE_ENABLE_COLUMN_METADATA
5560
/**
5661
* @brief Return a pointer to the table column name that is the origin of this result column
5762
*

src/SQLiteC++.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@
3838
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
3939
* numbers used in [SQLITECPP_VERSION].
4040
*/
41-
#define SQLITECPP_VERSION "0.5.1"
42-
#define SQLITECPP_VERSION_NUMBER 0005001
41+
#define SQLITECPP_VERSION "0.6.0"
42+
#define SQLITECPP_VERSION_NUMBER 0006000

0 commit comments

Comments
 (0)