Skip to content

Commit 18c8049

Browse files
Set Text type to sqlite3 text type
1 parent 9ca0105 commit 18c8049

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

sqlite3pp_ez.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,19 +1298,22 @@ namespace sqlite3pp
12981298
TypeName = str_toupper(TypeName);
12991299
if (!m_options.m.initialize_member_variables)
13001300
return "";
1301-
if (TypeName == "TEXT")
1302-
return " = " + m_options.s.str_pre + "\"\"" + m_options.s.str_post;
1303-
if (TypeName == "TEXT" || TypeName == "Character" || TypeName == "Varchar")
1304-
return " = \"\"";
1305-
if (TypeName == "Nchar" || TypeName == "Nvarchar")
1306-
return " = " + m_options.s.str_pre + "\"\"" + m_options.s.str_post;
13071301
if (TypeName == "BOOLEAN")
13081302
return " = false";
13091303
if (TypeName == "INTEGER" || TypeName == "INT" || TypeName == "INT2" || TypeName == "INT8" || TypeName == "TINYINT" ||
13101304
TypeName == "Smallint" || TypeName == "Mediumint" || TypeName == "Bigint" || TypeName == "UBigint")
13111305
return " = 0";
13121306
if (TypeName == "REAL" || TypeName == "DOUBLEPRCSN" || TypeName == "NUMERIC" || TypeName == "DECIMAL" || TypeName == "DOUBLE" || TypeName == "FLOAT")
13131307
return " = 0.0f";
1308+
if (m_options.m.initialize_str_member_var)
1309+
{
1310+
if (TypeName == "TEXT")
1311+
return " = " + m_options.s.str_pre + "\"\"" + m_options.s.str_post;
1312+
if (TypeName == "TEXT" || TypeName == "Character" || TypeName == "Varchar")
1313+
return " = \"\"";
1314+
if (TypeName == "Nchar" || TypeName == "Nvarchar")
1315+
return " = " + m_options.s.str_pre + "\"\"" + m_options.s.str_post;
1316+
}
13141317
return "";
13151318
}
13161319

@@ -1345,14 +1348,28 @@ namespace sqlite3pp
13451348
return false;
13461349
m_ClassNames.push_back(ClassName);
13471350
////////////////////////////////////////////////////////////////////////////////////////////
1348-
// Create Table/View class, and create a define type for strings
1349-
myfile << "\nclass " << ClassName << ": public sqlite3pp::sql_base\n{\npublic:" << std::endl;
1350-
myfile << "\tusing StrType = " << m_options.s.str_type << ";\n\tusing Text = StrType;" << std::endl;
1351+
// Create Table/View class
1352+
myfile << "\nclass " << ClassName << ": public sqlite3pp::sql_base\n{" << std::endl;
13511353

13521354
if (!m_options.m.exclude_table_interface)
13531355
{
13541356
if (!m_options.m.exclude_comments)
1355-
myfile << "\n\t// Constructors" << std::endl;
1357+
myfile << "\t// A member variable for each field in the table" << std::endl;
1358+
// Define if data member variables are protected or public
1359+
const char* publicOrPrivate = m_options.m.is_public_var_members ? "public" : "protected";
1360+
myfile << publicOrPrivate << ":" << std::endl;
1361+
1362+
// Define data member variables associated with the table/view
1363+
for (auto& c : columns)
1364+
myfile << "\t" << c.second << " " << c.first << InitializeValue(c.second) << ";" << std::endl;
1365+
1366+
myfile << "\npublic:" << std::endl;
1367+
// Create a define type for strings
1368+
myfile << "\tusing StrType = " << m_options.s.str_type << ";" << std::endl;
1369+
//myfile << "\n\tusing Text = StrType;" << std::endl;
1370+
1371+
if (!m_options.m.exclude_comments)
1372+
myfile << "\t// Constructors" << std::endl;
13561373
// These constructors are only useful if method setData is created.
13571374
myfile << "\t" << ClassName << "() {}"; // Allow default constructor to still work
13581375
if (!m_options.m.exclude_comments)
@@ -1432,15 +1449,6 @@ namespace sqlite3pp
14321449
myfile << "\tvoid set_" << c.first << "(const " << c.second << "& data__) {" << c.first << " = data__;}" << std::endl;
14331450
}
14341451

1435-
if (!m_options.m.exclude_comments)
1436-
myfile << "\n\t// A member variable for each field in the table" << std::endl;
1437-
// Define if data member variables are protected or public
1438-
const char* publicOrPrivate = m_options.m.is_public_var_members ? "public" : "protected";
1439-
myfile << publicOrPrivate << ":" << std::endl;
1440-
// Define data member variables associated with the table/view
1441-
for (auto& c : columns)
1442-
myfile << "\t" << c.second << " " << c.first << InitializeValue(c.second) << ";" << std::endl;
1443-
14441452
const std::string OperatorStreamComment1 = "/* sqlite3pp::TableOStream container interface.\n\tFunctions OStream(), operator<<(), and Delimiter() are required when using the sqlite3pp::TableOStream container.\n\tExample Usage:\t\t(Using sqlite3pp::TableOStream container)\n\t\t\tTableOStream<" + ClassName + "> tbl(DbFileNameArg(\"myDatabase.db\"));\n\t\t\ttbl.setDelimit(\"|\"); // Change delimiter\n\t\t\tstd::cout << tbl; // Send data to screen with the changed delimiter\n\n\t\t\tstd::ofstream ofs (\"data.csv\", std::ofstream::out);\n\t\t\ttbl.setDelimit(\",\"); // Change delimiter\n\t\t\tofs << tbl; // Write data to a CSV file using the changed \",\" delimiter.\n\n\t\t\ttbl.out(std::cout); // Send data to screen using out() member function.\n\tTo exclude TableOStream interface, set exclude_ostream_operator to true when creating this class using SQLiteClassBuilder.\n\t*/\n";
14451453
const char* OperatorStreamComment2 = "// sqlite3pp::TableOStream container interface.\n";
14461454
if (m_options.m.exclude_ostream_operator != true)

sqlite3pp_ez.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace sqlite3pp
7979
using Nvarchar = std::wstring;
8080
using Character = std::string;
8181
using Varchar = std::string;
82+
using Text = sqlite3pp::TEXT;
8283

8384

8485
friend database& setGlobalDB( const std::string& db_filename, ActionIfDatabaseOpen actionifopen);
@@ -477,6 +478,7 @@ namespace sqlite3pp
477478
bool exclude_main_hdr_example = false; // If true, excludes example code added to sql_Master_Header.h
478479
bool exclude_comment_out_example = false;// If true, does NOT comment out example code
479480
bool initialize_member_variables = true;// If true, initialize class member variables in header
481+
bool initialize_str_member_var = false; // If true, initialize class member string variables in header
480482
}; // Create a custom defined TblClassOptions variable, or used one of the SQLiteClassBuilder predefined types, or use the default type which is automatically set by the SQLiteClassBuilder constructor
481483

482484
struct TblClassOptions

0 commit comments

Comments
 (0)