Skip to content

Commit 7138783

Browse files
Fixed bug with get
1 parent 8624dfd commit 7138783

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

sqlite3pp.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,28 @@ namespace sqlite3pp
546546
}
547547

548548
char const* query::rows::get( int idx, char const* ) const
549-
{
550-
return reinterpret_cast<char const*>(SQLITEDLLCONNECT sqlite3_column_text( stmt_, idx ));
549+
{ // [David Maisonave changes] -- Fixed bug when using types other than SQLITE_TEXT.
550+
int type = SQLITEDLLCONNECT sqlite3_column_type(stmt_, idx);
551+
if (type == SQLITE_TEXT)
552+
return reinterpret_cast<char const*>(SQLITEDLLCONNECT sqlite3_column_text( stmt_, idx ));
553+
if (type == SQLITE_INTEGER)
554+
{
555+
int number = SQLITEDLLCONNECT sqlite3_column_int(stmt_, idx);
556+
std::string str_number = std::to_string(number);
557+
return str_number.c_str();
558+
}
559+
if (type == SQLITE_FLOAT)
560+
{
561+
double number = SQLITEDLLCONNECT sqlite3_column_double(stmt_, idx);
562+
std::string str_number = std::to_string(number);
563+
return str_number.c_str();
564+
}
565+
if (type == SQLITE_BLOB)
566+
{
567+
const char* value = reinterpret_cast<char const*>(SQLITEDLLCONNECT sqlite3_column_blob(stmt_, idx));
568+
return value;
569+
}
570+
return "";
551571
}
552572

553573
std::string query::rows::get( int idx, std::string ) const

sqlite3pp_ez.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ namespace sqlite3pp
938938
using StrType = std::string;
939939
static StrType getTableName() { return "sqlite_master"; }
940940
static StrType getColumnNames() { return "type, name, tbl_name, rootpage, sql"; }
941-
static StrType getSelecColumnNames() { return "type, name, tbl_name, rootpage, sql"; }
941+
static StrType getSelectColumnNames() { return "type, name, tbl_name, rootpage, sql"; }
942942
template<class T> void getStreamData(T q) { q.getter() >> type >> name >> tbl_name >> rootpage >> sql; }
943943
static int getColumnCount() { return 5; }
944944
public:
@@ -1316,7 +1316,7 @@ namespace sqlite3pp
13161316
// The pragma should return columns (cid, name, type, notnull, dflt_value, pk)
13171317
const char* CommentSection = "////////////////////////////////////////////////////////////////////////////////////////////";
13181318
if (QueryStr.empty())
1319-
QueryStr = "SELECT * FROM \"" + TableName + "\"";
1319+
QueryStr = "SELECT * FROM '" + TableName + "'";
13201320
std::shared_ptr < sqlite3pp::query> qry(sql_base::CreateQuery(m_db, QueryStr));
13211321
if (!qry)
13221322
return false;
@@ -1374,7 +1374,7 @@ namespace sqlite3pp
13741374
myfile << std::endl;
13751375

13761376
if (!m_options.m.exclude_comments)
1377-
myfile << "\n\t// getTableName, getColumnNames, getSelecColumnNames, and getStreamData are required for sqlite3pp::Table template class" << std::endl;
1377+
myfile << "\n\t// getTableName, getColumnNames, getSelectColumnNames, and getStreamData are required for sqlite3pp::Table template class" << std::endl;
13781378

13791379
// Create getTableName member function. Needed for sqlite3pp::Table template class
13801380
myfile << "\tstatic StrType getTableName() { return " << m_options.s.str_pre << "\"" << TableName << "\" " << m_options.s.str_post << "; }" << std::endl;
@@ -1385,10 +1385,10 @@ namespace sqlite3pp
13851385
myfile << c.second << c.first;
13861386
myfile << "\"" << m_options.s.str_post << "; }" << std::endl;
13871387

1388-
// Create getSelecColumnNames member function. Needed for sqlite3pp::Table template class
1389-
myfile << "\tstatic StrType getSelecColumnNames() { return " << m_options.s.str_pre << "\"";
1388+
// Create getSelectColumnNames member function. Needed for sqlite3pp::Table template class
1389+
myfile << "\tstatic StrType getSelectColumnNames() { return " << m_options.s.str_pre << "\"";
13901390
for (auto& c : columns_with_comma)
1391-
myfile << c.second << "\\\"" << c.first << "\\\"";
1391+
myfile << c.second << "'" << c.first << "'";
13921392
myfile << "\"" << m_options.s.str_post << "; }" << std::endl;
13931393

13941394
// Create GetValues member function. Needed for sqlite3pp::Table template class

sqlite3pp_ez.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ namespace sqlite3pp
299299
void Insert(const DataType &d) { push_back(d); Insert(ValueArg(d.GetValues()), T_STR()); }
300300
void UpdateDb(const DataType &d) { UpdateDb(ValueArg(d.GetValues()), T_STR()); }
301301
void DeleteAll(){ DeleteAll(T_STR()); }
302-
std::string CreateSelectQueryStr(WhereClauseArg whereclausearg, std::string) { return "SELECT " + T::getSelecColumnNames() + " FROM \"" + T::getTableName() + "\" " + to_string(whereclausearg.get_Str().c_str()); }
303-
std::wstring CreateSelectQueryStr(WhereClauseArg whereclausearg, std::wstring) { return L"SELECT " + T::getSelecColumnNames() + L" FROM \"" + T::getTableName() + L"\" " + to_wstring(whereclausearg.get_Str().c_str()); }
302+
std::string CreateSelectQueryStr(WhereClauseArg whereclausearg, std::string) { return "SELECT " + T::getSelectColumnNames() + " FROM '" + T::getTableName() + "' " + to_string(whereclausearg.get_Str().c_str()); }
303+
std::wstring CreateSelectQueryStr(WhereClauseArg whereclausearg, std::wstring) { return L"SELECT " + T::getSelectColumnNames() + L" FROM '" + T::getTableName() + L"' " + to_wstring(whereclausearg.get_Str().c_str()); }
304304
void ReQuery()
305305
{
306306
m_VectType.clear();

0 commit comments

Comments
 (0)