Skip to content

Commit f89656f

Browse files
added operator<< for Text type
1 parent 7f5234a commit f89656f

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

sqlite3pp_ez.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -835,19 +835,7 @@ namespace sqlite3pp
835835
return data;
836836
}
837837

838-
static std::wostream& operator<<(std::wostream& os, const sql_base::Character& t)
839-
{
840-
os << to_wstring(t);
841-
return os;
842-
}
843-
844-
static std::ostream& operator<<(std::ostream& os, const sql_base::Nchar& t)
845-
{
846-
os << to_string(t);
847-
return os;
848-
}
849-
850-
static std::wostream& operator<<(std::wostream& os, const sqlite3pp::Blob& t)
838+
std::wostream& operator<<(std::wostream& os, const sqlite3pp::Blob& t)
851839
{
852840
std::string data(t->data(), t->data() + t->size());
853841
std::wstring wdata = to_wstring(data);
@@ -944,6 +932,17 @@ namespace sqlite3pp
944932
}
945933
return os;
946934
}
935+
936+
std::wostream& operator<<(std::wostream& os, const sqlite3pp::TEXT& obj) {
937+
os << sqlite3pp::to_wstring(obj).c_str();
938+
return os;
939+
}
940+
941+
std::ostream& operator<<(std::ostream& os, const sqlite3pp::TEXT& obj) {
942+
os << sqlite3pp::to_string(obj).c_str();
943+
return os;
944+
}
945+
947946
#endif // !SQLITE3PP_CONVERT_TO_RESULTING_AFFINITY
948947

949948

@@ -1088,9 +1087,9 @@ namespace sqlite3pp
10881087
return "Float";
10891088

10901089
// String types
1091-
if (strcmp("TEXT", str) == 0)
1090+
if (strcmp("TEXT", str) == 0 || str_type.find(" SUB_TYPE TEXT") != std::string::npos)
10921091
return "Text";
1093-
if (str_type.find("CHARACTER") == 0)
1092+
if (str_type.find("CHAR") == 0)
10941093
return "Character";
10951094
if (str_type.find("VARYING CHARACTER") == 0
10961095
|| str_type.find("VARCHAR") == 0)
@@ -1100,6 +1099,9 @@ namespace sqlite3pp
11001099
return "Nchar";
11011100
if (str_type.find("NVARCHAR") == 0)
11021101
return "Nvarchar";
1102+
1103+
if (strcmp("TIMESTAMP", str) == 0)
1104+
return "Bigint";
11031105
}
11041106

11051107
V_COUT(WARN, "Received unknown type ('" << str_org << "') from DB for column '" << colName << "' in table/view '" << tblVw << "'.");
@@ -1196,31 +1198,35 @@ namespace sqlite3pp
11961198
if (columns.size() > 0)
11971199
{
11981200
std::string outType = "std::cout";
1199-
for (auto& c : columns)
1200-
if (c.second == "Text")
1201-
outType = "std::wcout";
1201+
std::string ColumnSep = " << \" | \"";
1202+
//for (auto& c : columns)
1203+
// if (c.second == "Text")
1204+
// {
1205+
// outType = "std::wcout";
1206+
// ColumnSep = " << L\" | \"";
1207+
// }
12021208
myfile << "\t// Example #4\n\t\tsqlite3pp::setGlobalDB(\"myDatabase.db\");" << std::endl;
12031209
myfile << "\t\tsqlite3pp::Table<" << ClassName << "> my_tbl;";
12041210

12051211
myfile << "\n\t\t// Example#4a -- (C++11) Range-based loop";
12061212
myfile << "\n\t\tfor(auto row : my_tbl)\n";
12071213
myfile << "\t\t\t" << outType;
12081214
for (auto& c : columns)
1209-
myfile << " << row.get_" << c.first << "()";
1215+
myfile << " << row.get_" << c.first << "()" << ColumnSep;
12101216
myfile << " << std::endl;" << std::endl;
12111217

12121218
myfile << "\n\t\t// Example#4b -- C++ style iteration";
12131219
myfile << "\n\t\tfor (auto row = my_tbl.begin(); row != my_tbl.end(); ++row) \n";
12141220
myfile << "\t\t\t" << outType;
12151221
for (auto& c : columns)
1216-
myfile << " << row->get_" << c.first << "()";
1222+
myfile << " << row->get_" << c.first << "()" << ColumnSep;
12171223
myfile << " << std::endl;" << std::endl;
12181224

12191225
myfile << "\n\t\t// Example#4c -- C style iteration";
12201226
myfile << "\n\t\tfor (int row = 0; row < my_tbl.size(); ++row) \n";
12211227
myfile << "\t\t\t" << outType;
12221228
for (auto& c : columns)
1223-
myfile << " << my_tbl[row].get_" << c.first << "()";
1229+
myfile << " << my_tbl[row].get_" << c.first << "()" << ColumnSep;
12241230
myfile << " << std::endl;" << std::endl;
12251231
}
12261232
myfile << TopHeaderCommnetsPrt2 << std::endl;
@@ -1372,7 +1378,7 @@ namespace sqlite3pp
13721378
// The pragma should return columns (cid, name, type, notnull, dflt_value, pk)
13731379
const char* CommentSection = "////////////////////////////////////////////////////////////////////////////////////////////";
13741380
if (QueryStr.empty())
1375-
QueryStr = "SELECT * FROM '" + TableName + "'";
1381+
QueryStr = "SELECT * FROM \"" + TableName + "\"";
13761382
std::shared_ptr < sqlite3pp::query> qry(sql_base::CreateQuery(m_db, QueryStr));
13771383
if (!qry)
13781384
return false;
@@ -1444,7 +1450,7 @@ namespace sqlite3pp
14441450
// Create getSelectColumnNames member function. Needed for sqlite3pp::Table template class
14451451
myfile << "\tstatic StrType getSelectColumnNames() { return " << m_options.s.str_pre << "\"";
14461452
for (auto& c : columns_with_comma)
1447-
myfile << c.second << "'" << c.first << "'";
1453+
myfile << c.second << "\\\"" << c.first << "\\\"";
14481454
myfile << "\"" << m_options.s.str_post << "; }" << std::endl;
14491455

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

sqlite3pp_ez.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ namespace sqlite3pp
114114
static void set(tstring db_filename);
115115
static void unset();
116116
};
117-
118117

119118
std::string to_string(const std::wstring &src);
120119
std::string to_string(const std::string &src);// For template usage
@@ -242,7 +241,8 @@ namespace sqlite3pp
242241
Table(sqlite3pp::database &db, DbFileNameArg dbfilenamearg, PreExecuteArg preexecutearg, WhereClauseArg whereclausearg = WhereClauseArg()) :m_PreExecute(preexecutearg), m_WhereClause(whereclausearg), m_DbFileName(dbfilenamearg), m_db(db), m_InitQuery(CreateSelectQueryStr(whereclausearg, T_STR())), m_TableName(T::getTableName()), m_ColumnNames(T::getColumnNames()), m_ColumnCount(T::getColumnCount()) { ExecuteQuery(m_db, m_InitQuery, preexecutearg, dbfilenamearg); }
243242

244243
// Same as above set, but this set uses the single global database instance, and so db does not need to be pass to the constructor. These constructors automatically populate the object using data from the global database instance.
245-
Table(WhereClauseArg whereclausearg = WhereClauseArg() , PreExecuteArg preexecutearg = PreExecuteArg(), DbFileNameArg dbfilenamearg = DbFileNameArg()):m_PreExecute(preexecutearg), m_WhereClause(whereclausearg), m_DbFileName(dbfilenamearg), m_db( global_db ), m_InitQuery(CreateSelectQueryStr(whereclausearg, T_STR())), m_TableName(T::getTableName()), m_ColumnNames(T::getColumnNames()), m_ColumnCount(T::getColumnCount()) { ExecuteQuery( m_db, m_InitQuery, preexecutearg, dbfilenamearg); }
244+
Table(WhereClauseArg whereclausearg = WhereClauseArg() , PreExecuteArg preexecutearg = PreExecuteArg(), DbFileNameArg dbfilenamearg = DbFileNameArg()) // **Default Constructor**
245+
:m_PreExecute(preexecutearg), m_WhereClause(whereclausearg), m_DbFileName(dbfilenamearg), m_db( global_db ), m_InitQuery(CreateSelectQueryStr(whereclausearg, T_STR())), m_TableName(T::getTableName()), m_ColumnNames(T::getColumnNames()), m_ColumnCount(T::getColumnCount()) { ExecuteQuery( m_db, m_InitQuery, preexecutearg, dbfilenamearg); }
246246
Table(PreExecuteArg preexecutearg , WhereClauseArg whereclausearg = WhereClauseArg(), DbFileNameArg dbfilenamearg = DbFileNameArg()) :m_PreExecute(preexecutearg), m_WhereClause(whereclausearg), m_DbFileName(dbfilenamearg), m_db(global_db), m_InitQuery(CreateSelectQueryStr(whereclausearg, T_STR())), m_TableName(T::getTableName()), m_ColumnNames(T::getColumnNames()), m_ColumnCount(T::getColumnCount()) { ExecuteQuery( m_db, m_InitQuery, preexecutearg, dbfilenamearg); }
247247
Table(DbFileNameArg dbfilenamearg , WhereClauseArg whereclausearg = WhereClauseArg(), PreExecuteArg preexecutearg = PreExecuteArg()) :m_PreExecute(preexecutearg), m_WhereClause(whereclausearg), m_DbFileName(dbfilenamearg), m_db(global_db), m_InitQuery(CreateSelectQueryStr(whereclausearg, T_STR())), m_TableName(T::getTableName()), m_ColumnNames(T::getColumnNames()), m_ColumnCount(T::getColumnCount()) { ExecuteQuery( m_db, m_InitQuery, preexecutearg, dbfilenamearg); }
248248
Table(DbFileNameArg dbfilenamearg , PreExecuteArg preexecutearg, WhereClauseArg whereclausearg = WhereClauseArg()) :m_PreExecute(preexecutearg), m_WhereClause(whereclausearg), m_DbFileName(dbfilenamearg), m_db(global_db), m_InitQuery(CreateSelectQueryStr(whereclausearg, T_STR())), m_TableName(T::getTableName()), m_ColumnNames(T::getColumnNames()), m_ColumnCount(T::getColumnCount()) { ExecuteQuery( m_db, m_InitQuery, preexecutearg, dbfilenamearg); }
@@ -416,6 +416,8 @@ namespace sqlite3pp
416416
std::ostream& operator<<(std::ostream& os, const sqlite3pp::Datetime& t);
417417
std::wostream& operator<<(std::wostream& os, const sqlite3pp::Date& t);
418418
std::ostream& operator<<(std::ostream& os, const sqlite3pp::Date& t);
419+
std::wostream& operator<<(std::wostream& os, const sqlite3pp::TEXT& obj);
420+
std::ostream& operator<<(std::ostream& os, const sqlite3pp::TEXT& obj);
419421

420422
database& setGlobalDB(const std::string& db_filename, ActionIfDatabaseOpen actionifopen = AIO_SkipIfSameFile, bool disconnectExistingConnection = false);
421423
database& setGlobalDB(const std::wstring& db_filename, ActionIfDatabaseOpen actionifopen = AIO_SkipIfSameFile, bool disconnectExistingConnection = false);

0 commit comments

Comments
 (0)