Skip to content

Commit b5ca63b

Browse files
Added initialize variable logic
1 parent b813cb9 commit b5ca63b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

sqlite3pp_ez.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ namespace sqlite3pp
979979
return strtype;
980980
}
981981

982-
std::string SQLiteClassBuilder::GetType_s(const std::string &tblVw, const std::string &colName, const char* str_org)
982+
std::string SQLiteClassBuilder::GetType_s(const std::string &tblVw, const std::string &colName, const char* str_org) const
983983
{
984984
const std::string DefaultType = "Text";
985985
if (!str_org)
@@ -1286,6 +1286,32 @@ namespace sqlite3pp
12861286
}
12871287
return NULL;
12881288
}
1289+
std::string str_toupper(std::string s)
1290+
{
1291+
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::toupper(c); });
1292+
return s;
1293+
}
1294+
1295+
std::string SQLiteClassBuilder::InitializeValue(std::string TypeName) const
1296+
{
1297+
TypeName = str_toupper(TypeName);
1298+
if (!m_options.m.initialize_member_variables)
1299+
return "";
1300+
if (TypeName == "TEXT")
1301+
return " = " + m_options.s.str_pre + "\"\"" + m_options.s.str_post;
1302+
if (TypeName == "TEXT" || TypeName == "Character" || TypeName == "Varchar")
1303+
return " = \"\"";
1304+
if (TypeName == "Nchar" || TypeName == "Nvarchar")
1305+
return " = " + m_options.s.str_pre + "\"\"" + m_options.s.str_post;
1306+
if (TypeName == "BOOLEAN")
1307+
return " = false";
1308+
if (TypeName == "INTEGER" || TypeName == "INT" || TypeName == "INT2" || TypeName == "INT8" || TypeName == "TINYINT" ||
1309+
TypeName == "Smallint" || TypeName == "Mediumint" || TypeName == "Bigint" || TypeName == "UBigint")
1310+
return " = 0";
1311+
if (TypeName == "REAL" || TypeName == "DOUBLEPRCSN" || TypeName == "NUMERIC" || TypeName == "DECIMAL" || TypeName == "DOUBLE" || TypeName == "FLOAT")
1312+
return " = 0.0f";
1313+
return "";
1314+
}
12891315

12901316
bool SQLiteClassBuilder::ProcessClassCreation(const std::string& TableName, std::string QueryStr)
12911317
{
@@ -1412,7 +1438,7 @@ namespace sqlite3pp
14121438
myfile << publicOrPrivate << ":" << std::endl;
14131439
// Define data member variables associated with the table/view
14141440
for (auto& c : columns)
1415-
myfile << "\t" << c.second << " " << c.first << ";" << std::endl;
1441+
myfile << "\t" << c.second << " " << c.first << InitializeValue(c.second) << ";" << std::endl;
14161442

14171443
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";
14181444
const char* OperatorStreamComment2 = "// sqlite3pp::TableOStream container interface.\n";

sqlite3pp_ez.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ namespace sqlite3pp
476476
bool use_basic_types_only = false; // If true, only int, double, std::string, and std::wstring are used
477477
bool exclude_main_hdr_example = false; // If true, excludes example code added to sql_Master_Header.h
478478
bool exclude_comment_out_example = false;// If true, does NOT comment out example code
479+
bool initialize_member_variables = true;// If true, initialize class member varibles in header
479480
}; // 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
480481

481482
struct TblClassOptions
@@ -494,7 +495,7 @@ namespace sqlite3pp
494495
std::vector<std::string> m_HeadersCreated;
495496
std::vector<std::string> m_ClassNames;
496497
std::string GetType(const std::string &tblVw, const std::string &colName, const char* str);
497-
std::string GetType_s(const std::string &tblVw, const std::string &colName, const char* str);
498+
std::string GetType_s(const std::string &tblVw, const std::string &colName, const char* str) const;
498499
TblClassOptions Init(const StrOptions & stroptions, const MiscOptions & miscoptions, const HeaderOpt & headeropt);
499500
void Init(
500501
const std::string& TableOrView_name
@@ -529,6 +530,7 @@ namespace sqlite3pp
529530
const std::vector<std::string>& GetHeadersCreated() const { return m_HeadersCreated; }
530531
const std::vector<std::string>& GetClassNames() const { return m_ClassNames; }
531532
const std::string& GetDestFolder() const { return m_options.h.dest_folder; }
533+
std::string InitializeValue(std::string TypeName) const;
532534

533535
// Predefined string options
534536
static const StrOptions strOpt_std_string ; // TEXT type defaults to std::string

0 commit comments

Comments
 (0)