mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 17:56:13 -04:00
Adding a Column::getName() function
- thanks to a patch provided by Nellis Willers, - requires the SQLITE_ENABLE_COLUMN_METADATA preprocessor macro to be also defined at compile times of the SQLite library - v0.5.1
This commit is contained in:
parent
1f55ddbbdb
commit
7669bcbf90
@ -14,10 +14,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "../../src/Database.h"
|
#include "../../src/SQLiteC++.h"
|
||||||
#include "../../src/Statement.h"
|
|
||||||
#include "../../src/Column.h"
|
|
||||||
#include "../../src/Transaction.h"
|
|
||||||
|
|
||||||
|
|
||||||
static const char* filename_example_db3 = "examples/example1/example.db3";
|
static const char* filename_example_db3 = "examples/example1/example.db3";
|
||||||
@ -96,7 +93,9 @@ int main (void)
|
|||||||
int bytes = query.getColumn(1).getBytes();
|
int bytes = query.getColumn(1).getBytes();
|
||||||
double weight = query.getColumn(2); // = query.getColumn(2).getInt()
|
double weight = query.getColumn(2); // = query.getColumn(2).getInt()
|
||||||
|
|
||||||
std::cout << "row : (" << id << ", \"" << value2.c_str() << "\" " << bytes << "B, " << weight << ")\n";
|
std::string name(query.getColumn(0).getName());
|
||||||
|
|
||||||
|
std::cout << "row : (" << id << " [" << name.c_str() << "], \"" << value2.c_str() << "\" " << bytes << "B, " << weight << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the query to use it again
|
// Reset the query to use it again
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
** language. The code for the "sqlite3" command-line shell is also in a
|
** language. The code for the "sqlite3" command-line shell is also in a
|
||||||
** separate file. This file contains only code for the core SQLite library.
|
** separate file. This file contains only code for the core SQLite library.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define SQLITE_ENABLE_COLUMN_METADATA
|
||||||
#define SQLITE_CORE 1
|
#define SQLITE_CORE 1
|
||||||
#define SQLITE_AMALGAMATION 1
|
#define SQLITE_AMALGAMATION 1
|
||||||
#ifndef SQLITE_PRIVATE
|
#ifndef SQLITE_PRIVATE
|
||||||
|
@ -12,9 +12,11 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
namespace SQLite
|
namespace SQLite
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Encapsulation of a Column in a row of the result pointed by the prepared Statement.
|
// Encapsulation of a Column in a row of the result pointed by the prepared Statement.
|
||||||
Column::Column(Statement::Ptr& aStmtPtr, int aIndex) throw() : // nothrow
|
Column::Column(Statement::Ptr& aStmtPtr, int aIndex) throw() : // nothrow
|
||||||
mStmtPtr (aStmtPtr),
|
mStmtPtr (aStmtPtr),
|
||||||
@ -28,6 +30,14 @@ Column::~Column(void) throw() // nothrow
|
|||||||
// the finalization will be done by the destructor of the last shared pointer
|
// the finalization will be done by the destructor of the last shared pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||||
|
// Return the name of the column
|
||||||
|
const char * Column::getName(void) const throw() // nothrow
|
||||||
|
{
|
||||||
|
return sqlite3_column_origin_name(mStmtPtr, mIndex);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Return the integer value of the column specified by its index starting at 0
|
// Return the integer value of the column specified by its index starting at 0
|
||||||
int Column::getInt(void) const throw() // nothrow
|
int Column::getInt(void) const throw() // nothrow
|
||||||
{
|
{
|
||||||
@ -70,7 +80,6 @@ int Column::getBytes(void) const throw() // nothrow
|
|||||||
return sqlite3_column_bytes(mStmtPtr, mIndex);
|
return sqlite3_column_bytes(mStmtPtr, mIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Standard std::ostream inserter
|
// Standard std::ostream inserter
|
||||||
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn)
|
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn)
|
||||||
{
|
{
|
||||||
@ -78,4 +87,5 @@ std::ostream& operator<<(std::ostream& aStream, const Column& aColumn)
|
|||||||
return aStream;
|
return aStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace SQLite
|
} // namespace SQLite
|
||||||
|
22
src/Column.h
22
src/Column.h
@ -10,10 +10,20 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable APIs that provide convenient access to meta-data about tables and queries.
|
||||||
|
*
|
||||||
|
* @see #getName()
|
||||||
|
*
|
||||||
|
* @warning Requires this SQLITE_ENABLE_COLUMN_METADATA preprocessor macro to be also defined at compile times of the SQLite library.
|
||||||
|
*/
|
||||||
|
#define SQLITE_ENABLE_COLUMN_METADATA
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Statement.h"
|
#include "Statement.h"
|
||||||
|
|
||||||
|
|
||||||
namespace SQLite
|
namespace SQLite
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -43,6 +53,17 @@ public:
|
|||||||
// default copy constructor and assignment operator are perfectly suited :
|
// default copy constructor and assignment operator are perfectly suited :
|
||||||
// they copy the Statement::Ptr which in turn increments the reference counter.
|
// they copy the Statement::Ptr which in turn increments the reference counter.
|
||||||
|
|
||||||
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||||
|
/**
|
||||||
|
* @brief Return a pointer to the column name
|
||||||
|
*
|
||||||
|
* Require definition of the SQLITE_ENABLE_COLUMN_METADATA preprocessor macro :
|
||||||
|
* - for compilation of the SQLite library,
|
||||||
|
* - and also when compiling this wrapper.
|
||||||
|
*/
|
||||||
|
const char* getName (void) const throw(); // nothrow
|
||||||
|
#endif
|
||||||
|
|
||||||
/// @brief Return the integer value of the column.
|
/// @brief Return the integer value of the column.
|
||||||
int getInt (void) const throw(); // nothrow
|
int getInt (void) const throw(); // nothrow
|
||||||
/// @brief Return the 64bits integer value of the column.
|
/// @brief Return the 64bits integer value of the column.
|
||||||
@ -185,4 +206,5 @@ private:
|
|||||||
*/
|
*/
|
||||||
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn);
|
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn);
|
||||||
|
|
||||||
|
|
||||||
} // namespace SQLite
|
} // namespace SQLite
|
||||||
|
@ -37,5 +37,5 @@
|
|||||||
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
|
* with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
|
||||||
* numbers used in [SQLITECPP_VERSION].
|
* numbers used in [SQLITECPP_VERSION].
|
||||||
*/
|
*/
|
||||||
#define SQLITECPP_VERSION "0.5.0"
|
#define SQLITECPP_VERSION "0.5.1"
|
||||||
#define SQLITECPP_VERSION_NUMBER 0005000
|
#define SQLITECPP_VERSION_NUMBER 0005001
|
||||||
|
Loading…
x
Reference in New Issue
Block a user