Skip to content

Commit 9616dbb

Browse files
Fix spelling errors
1 parent 2b8f4b1 commit 9616dbb

File tree

2 files changed

+82
-78
lines changed

2 files changed

+82
-78
lines changed

sqlite3pp_ez.cpp

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,7 @@ SQLITE_EXTENSION_INIT3
2626
#include <cassert>
2727
#include <sys/types.h>
2828
#include <sys/stat.h>
29-
#include <direct.h>
3029

31-
bool DirExists(const std::string& dirName_in) {
32-
DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
33-
if (ftyp == INVALID_FILE_ATTRIBUTES) {
34-
return false; // Directory does not exist or an error occurred
35-
}
36-
return (ftyp & FILE_ATTRIBUTE_DIRECTORY) != 0; // Check if it's a directory
37-
}
38-
39-
bool DirExists(const std::wstring& dirName_in) {
40-
DWORD ftyp = GetFileAttributesW(dirName_in.c_str());
41-
if (ftyp == INVALID_FILE_ATTRIBUTES) {
42-
return false; // Directory does not exist or an error occurred
43-
}
44-
return (ftyp & FILE_ATTRIBUTE_DIRECTORY) != 0; // Check if it's a directory
45-
}
4630

4731
#define V_COUT(VB, V) {if (sqlite3pp::sql_base::GetVerbosityLevel() >= sqlite3pp::VBLV_##VB) {std::cout << __FUNCTION__ << ":" << #VB << ": " << V << std::endl;} }
4832

@@ -95,7 +79,7 @@ namespace sqlite3pp
9579
return src;
9680
}
9781

98-
// Convertion types
82+
// Conversion types
9983
std::string to_string(const Clob& src)
10084
{
10185
if (src)
@@ -164,14 +148,30 @@ namespace sqlite3pp
164148
return to_wstring(sqlite3pp::to_string(src));
165149
}
166150

167-
bool isValidDate(const Date& t)
151+
static bool isValidDate(const Date& t)
168152
{
169153
if (t.t < 1)
170154
return false;
171155
return true;
172156
}
173157

174-
bool isValidDate(const Datetime& t)
158+
static bool DirExists(const std::wstring& dirName_in)
159+
{
160+
DWORD ftyp = GetFileAttributesW(dirName_in.c_str());
161+
if (ftyp == INVALID_FILE_ATTRIBUTES)
162+
return false; // Directory does not exist or an error occurred
163+
return (ftyp & FILE_ATTRIBUTE_DIRECTORY) != 0; // Check if it's a directory
164+
}
165+
166+
static bool DirExists(const std::string& dirName_in)
167+
{
168+
DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
169+
if (ftyp == INVALID_FILE_ATTRIBUTES)
170+
return false; // Directory does not exist or an error occurred
171+
return (ftyp & FILE_ATTRIBUTE_DIRECTORY) != 0; // Check if it's a directory
172+
}
173+
174+
static bool isValidDate(const Datetime& t)
175175
{
176176
if (t.tm_struct.tm_sec < 0 || t.tm_struct.tm_sec > 60)
177177
return false;
@@ -393,7 +393,7 @@ namespace sqlite3pp
393393
if (!sql_base::bIsGlblDbOpen)
394394
throw database_error("Trying to Execute Global DB before it is opened. Query='" + to_string(sql.c_str()) + "'");
395395
int rc = sql_base::last_rc = sql_base::global_db.execute( sql.c_str() );
396-
// ToDo: Add logic here to repart error if rc!=SQLITE_OK
396+
// ToDo: Add logic here to report error if rc!=SQLITE_OK
397397
return rc;
398398
}
399399

@@ -582,7 +582,7 @@ namespace sqlite3pp
582582
return copy_file(to_wstring(Src), to_wstring(Dest), OverWriteIfExist);
583583
}
584584

585-
void replace_all(std::wstring & data, const std::wstring &toSearch, const std::wstring &replaceStr)
585+
static void replace_all(std::wstring & data, const std::wstring &toSearch, const std::wstring &replaceStr)
586586
{
587587
// Get the first occurrence
588588
size_t pos = data.find(toSearch);
@@ -596,7 +596,7 @@ namespace sqlite3pp
596596
}
597597
}
598598

599-
void CheckEnv(std::wstring &src, const std::string &VarName, const std::string VarNamePrefix, const std::string VarNamePostfix)
599+
static void CheckEnv(std::wstring &src, const std::string &VarName, const std::string VarNamePrefix, const std::string VarNamePostfix)
600600
{
601601
char env_p[_MAX_PATH] = { 0 };
602602
size_t Sz = 0;
@@ -815,19 +815,19 @@ namespace sqlite3pp
815815
return data;
816816
}
817817

818-
std::wostream& operator<<(std::wostream& os, const sql_base::Character& t)
818+
static std::wostream& operator<<(std::wostream& os, const sql_base::Character& t)
819819
{
820820
os << to_wstring(t);
821821
return os;
822822
}
823823

824-
std::ostream& operator<<(std::ostream& os, const sql_base::Nchar& t)
824+
static std::ostream& operator<<(std::ostream& os, const sql_base::Nchar& t)
825825
{
826826
os << to_string(t);
827827
return os;
828828
}
829829

830-
std::wostream& operator<<(std::wostream& os, const sqlite3pp::Blob& t)
830+
static std::wostream& operator<<(std::wostream& os, const sqlite3pp::Blob& t)
831831
{
832832
std::string data(t->data(), t->data() + t->size());
833833
std::wstring wdata = to_wstring(data);
@@ -862,7 +862,7 @@ namespace sqlite3pp
862862
if (isValidDate(t))
863863
{
864864
wchar_t buf[256] = { 0 };
865-
wcsftime(buf, sizeof(buf), L"%Y-%m-%d %H:%M:%S", &t.tm_struct);
865+
wcsftime(buf, sizeof(buf) / sizeof(wchar_t), L"%Y-%m-%d %H:%M:%S", &t.tm_struct);
866866
os << buf;
867867
}
868868
else
@@ -896,12 +896,12 @@ namespace sqlite3pp
896896
wchar_t buf[256] = { 0 };
897897
std::tm tm_struct = { 0 };
898898
gmtime_s(&tm_struct, &t.t);
899-
wcsftime(buf, sizeof(buf), L"%Y-%m-%d", &tm_struct);
899+
wcsftime(buf, sizeof(buf) / sizeof(wchar_t), L"%Y-%m-%d", &tm_struct);
900900
os << buf;
901901
}
902902
else
903903
{
904-
V_COUT(WARN, "t.t = Invalid Falue.");
904+
V_COUT(WARN, "t.t = Invalid Value.");
905905
os << L"0000-00-00";
906906
}
907907
return os;
@@ -919,7 +919,7 @@ namespace sqlite3pp
919919
}
920920
else
921921
{
922-
V_COUT(WARN, "t.t = Invalid Falue.");
922+
V_COUT(WARN, "t.t = Invalid Value.");
923923
os << "0000-00-00";
924924
}
925925
return os;
@@ -966,7 +966,7 @@ namespace sqlite3pp
966966
const MiscOptions SQLiteClassBuilder::MiscOpt_var = { ",", true, true, true, true, true, true, false, true, true };
967967
// Default settings for HeaderOpt
968968
const HeaderOpt SQLiteClassBuilder::HeadersCreatedSqlDir = { "SQL\\", "sql_", "", "h", "..\\sqlite3pp_ez.h" };
969-
const HeaderOpt SQLiteClassBuilder::HeadersCreadedBaseDir = { "", "sql_", "", "h", "sqlite3pp_ez.h" };
969+
const HeaderOpt SQLiteClassBuilder::HeadersCreatedBaseDir = { "", "sql_", "", "h", "sqlite3pp_ez.h" };
970970

971971
const char *SQLiteClassBuilder::Nill = "#NILL#";
972972
const char *SQLiteClassBuilder::CreateHeaderForAllTables = "%_CreateHeaderForAllTables_%";
@@ -1137,20 +1137,24 @@ namespace sqlite3pp
11371137
ClassName = m_options.h.header_prefix + TableName + m_options.h.header_postfix;
11381138
const std::string HeaderFileName = ClassName + "." + m_options.h.file_type;
11391139
if (!DirExists(m_options.h.dest_folder))
1140-
_mkdir(m_options.h.dest_folder.c_str());
1140+
if (_mkdir(m_options.h.dest_folder.c_str()) != 0)
1141+
{
1142+
V_COUT(ERROR, "Failed to create folder '" << m_options.h.dest_folder << "'");
1143+
return false;
1144+
}
11411145
const std::string HeaderFileNameWithFolder = m_options.h.dest_folder + HeaderFileName;
11421146
myfile.open(HeaderFileNameWithFolder.c_str(), openMode);
11431147
if (!myfile.is_open())
11441148
{
1145-
V_COUT(WARN, "Failed to open file '" << HeaderFileNameWithFolder << "'");
1149+
V_COUT(ERROR, "Failed to open file '" << HeaderFileNameWithFolder << "'");
11461150
return false;
11471151
}
11481152
if (AppendToVect)
11491153
m_HeadersCreated.push_back(HeaderFileName);
1150-
char headerupper[256] = { 0 };
1151-
strcpy_s(headerupper, (ClassName + "_H").c_str());
1152-
_strupr_s(headerupper);
1153-
HeaderUpper = headerupper;
1154+
char headerUpper[256] = { 0 };
1155+
strcpy_s(headerUpper, (ClassName + "_H").c_str());
1156+
_strupr_s(headerUpper);
1157+
HeaderUpper = headerUpper;
11541158
if (!m_options.m.exclude_comments && AppendToVect == true)
11551159
{
11561160
myfile << TopHeaderCommnetsPrt1 << std::endl;
@@ -1159,20 +1163,20 @@ namespace sqlite3pp
11591163
if (LastColumnName.empty())
11601164
LastColumnName = "ColumnWiget";
11611165
myfile << "Example Usage:\t\t(Using sqlite3pp::Table container)" << std::endl;
1162-
myfile << "\t// Exampel #1\n\t\tsqlite3pp::setGlobalDB(\"mydatabase.db\");" << std::endl;
1166+
myfile << "\t// Example #1\n\t\tsqlite3pp::setGlobalDB(\"myDatabase.db\");" << std::endl;
11631167
myfile << "\t\tsqlite3pp::Table<" << ClassName << "> my_tbl;\n\t\tfor (auto row : my_tbl)\n\t\t\tstd::wcout << row << std::endl;\n" << std::endl;
11641168

1165-
myfile << "\t// Exampel #2\n\t\tfor (int i = 0; i < my_tbl.size(); ++i)\n\t\t\tstd::wcout << my_tbl[i].get_" << FirstColumnName << "() << std::endl;\n" << std::endl;
1169+
myfile << "\t// Example #2\n\t\tfor (int i = 0; i < my_tbl.size(); ++i)\n\t\t\tstd::wcout << my_tbl[i].get_" << FirstColumnName << "() << std::endl;\n" << std::endl;
11661170

1167-
myfile << "\t// Exampel #3\n\t\tfor (auto r = my_tbl.begin(); r != my_tbl.end(); ++r)\n\t\t\tstd::wcout << r->get_" << LastColumnName << "() << std::endl;\n" << std::endl;
1171+
myfile << "\t// Example #3\n\t\tfor (auto r = my_tbl.begin(); r != my_tbl.end(); ++r)\n\t\t\tstd::wcout << r->get_" << LastColumnName << "() << std::endl;\n" << std::endl;
11681172
myfile << TopHeaderCommnetsPrt2 << std::endl;
11691173
}
11701174
// Add includes needed to support specified m_options.str_type
11711175
myfile << "#ifndef " << HeaderUpper << std::endl;
11721176
myfile << "#define " << HeaderUpper << std::endl;
11731177
const std::string AdditionalInclude = "#include \"" + m_options.h.header_include + "\"";
11741178
if (m_options.s.str_include.size() && m_options.s.str_include != AdditionalInclude &&
1175-
(m_options.s.str_include != strOpt_sql_tstring.str_include || (m_options.h.header_include != HeadersCreatedSqlDir.header_include && m_options.h.header_include != HeadersCreadedBaseDir.header_include) ))
1179+
(m_options.s.str_include != strOpt_sql_tstring.str_include || (m_options.h.header_include != HeadersCreatedSqlDir.header_include && m_options.h.header_include != HeadersCreatedBaseDir.header_include) ))
11761180
myfile << m_options.s.str_include << std::endl;
11771181

11781182
if (m_options.h.header_include.size())
@@ -1191,7 +1195,7 @@ namespace sqlite3pp
11911195
using SQLiteMaster = Table<sqlite_master>;
11921196
SQLiteMaster tbl(m_db, WhereClauseArg(T_("where (type = 'table' or type = 'view') ") + to_tstring(AndWhereClause)));
11931197

1194-
for (auto t : tbl)
1198+
for (auto& t : tbl)
11951199
{
11961200
m_options.h.header_prefix = OrgPrefix + t.type + "_";
11971201
ProcessClassCreation(t.tbl_name);
@@ -1201,18 +1205,18 @@ namespace sqlite3pp
12011205
std::string ClassName, HeaderUpper;
12021206
if (CreateHeaderPrefix("Master_Header", myfile, ClassName, HeaderUpper, "", "", false))
12031207
{
1204-
for (auto s : m_HeadersCreated)
1208+
for (auto& s : m_HeadersCreated)
12051209
myfile << "#include \"" << s << "\"" << std::endl;
12061210
if (!m_options.m.exclude_main_hdr_example)
12071211
{
12081212
myfile << "\n" << std::endl;
1209-
if (!m_options.m.exclude_comment_out_exampl)
1213+
if (!m_options.m.exclude_comment_out_example)
12101214
myfile << "/*" << std::endl;
12111215
if (!m_options.m.exclude_comments)
12121216
{
12131217
myfile << "// This example code can be used to test and validate all tables." << std::endl;
12141218
myfile << "// Example Usage:" << std::endl;
1215-
myfile << "// \t\tqlite3pp::setGlobalDB(\"mydatabase.db\")" << std::endl;
1219+
myfile << "// \t\tsqlite3pp::setGlobalDB(\"myDatabase.db\")" << std::endl;
12161220
myfile << "// \t\tsqlite3pp::testAllTables();" << std::endl;
12171221
myfile << "// Warning: testPopulatingAllTables and testAllTables may take a very long time on a database with a lot of content." << std::endl;
12181222
}
@@ -1223,7 +1227,7 @@ namespace sqlite3pp
12231227
myfile << "\t// Function to test populating all tables & views." << std::endl;
12241228
myfile << "\tstd::map< std::string, std::shared_ptr<sqlite3pp::TableBase> > testPopulatingAllTables()\n\t{" << std::endl;
12251229
myfile << "\t\tstd::map< std::string, std::shared_ptr < sqlite3pp::TableBase>> Tables;" << std::endl;
1226-
for (auto s : m_ClassNames)
1230+
for (auto& s : m_ClassNames)
12271231
myfile << "\t\tTables[\"" << s << "\"] = std::shared_ptr<sqlite3pp::TableBase>(new sqlite3pp::Table<" << s << ">());" << std::endl;
12281232
myfile << "\t\treturn Tables;\n\t}" << std::endl;
12291233

@@ -1237,7 +1241,7 @@ namespace sqlite3pp
12371241
myfile << "\t}" << std::endl;
12381242

12391243
myfile << "}" << std::endl;
1240-
if (!m_options.m.exclude_comment_out_exampl)
1244+
if (!m_options.m.exclude_comment_out_example)
12411245
myfile << "*/" << std::endl;
12421246
myfile << "\n" << std::endl;
12431247
}
@@ -1249,7 +1253,7 @@ namespace sqlite3pp
12491253
return true;
12501254
}
12511255

1252-
bool IsStrType(const char* str)
1256+
static bool IsStrType(const char* str)
12531257
{
12541258
if (strcmp("Text", str) == 0 || strcmp("StrType", str) == 0 || strncmp("Character", str, 9) == 0 || strncmp("Varchar", str, 7) == 0)
12551259
return true;
@@ -1336,24 +1340,24 @@ namespace sqlite3pp
13361340
myfile << "\n\t// getTableName, getColumnNames, getSelecColumnNames, and getStreamData are required for sqlite3pp::Table template class" << std::endl;
13371341

13381342
// Create getTableName member function. Needed for sqlite3pp::Table template class
1339-
myfile << "\tstatic StrType getTableName() { return " << m_options.s.str_pre << " \"" << TableName << "\" " << m_options.s.str_post << "; }" << std::endl;
1343+
myfile << "\tstatic StrType getTableName() { return " << m_options.s.str_pre << "\"" << TableName << "\" " << m_options.s.str_post << "; }" << std::endl;
13401344

13411345
// Create getColumnNames member function. Needed for sqlite3pp::Table template class
1342-
myfile << "\tstatic StrType getColumnNames() { return " << m_options.s.str_pre << " \"";
1343-
for (auto c : columns_with_comma)
1346+
myfile << "\tstatic StrType getColumnNames() { return " << m_options.s.str_pre << "\"";
1347+
for (auto& c : columns_with_comma)
13441348
myfile << c.second << c.first;
13451349
myfile << "\"" << m_options.s.str_post << "; }" << std::endl;
13461350

13471351
// Create getSelecColumnNames member function. Needed for sqlite3pp::Table template class
1348-
myfile << "\tstatic StrType getSelecColumnNames() { return " << m_options.s.str_pre << " \"";
1349-
for (auto c : columns_with_comma)
1352+
myfile << "\tstatic StrType getSelecColumnNames() { return " << m_options.s.str_pre << "\"";
1353+
for (auto& c : columns_with_comma)
13501354
myfile << c.second << "\\\"" << c.first << "\\\"";
13511355
myfile << "\"" << m_options.s.str_post << "; }" << std::endl;
13521356

13531357
// Create GetValues member function. Needed for sqlite3pp::Table template class
13541358
myfile << "\tStrType GetValues() const\n\t{\n\t\tStrType strtype;";
13551359
std::string commaDel;
1356-
for (auto c : columns)
1360+
for (auto& c : columns)
13571361
{
13581362
myfile << "\n\t\tstrtype += " << m_options.s.str_pre << "\"" << commaDel << "'\"" << m_options.s.str_post
13591363
<< " + " << m_options.s.str_tostr << "( " << c.first << ") + " << m_options.s.str_pre << "\"'\"" << m_options.s.str_post << ";";
@@ -1363,13 +1367,13 @@ namespace sqlite3pp
13631367

13641368
// Create getStreamData member function. Needed for sqlite3pp::Table template class
13651369
myfile << "\ttemplate<class T> void getStreamData( T q ) { q.getter() ";
1366-
for (auto c : columns)
1370+
for (auto& c : columns)
13671371
myfile << " >> " << c.first;
13681372
myfile << ";}" << std::endl;
13691373

13701374
// Create setData member function. Used to transfer data from different tables/views having same data types and column names
13711375
myfile << "\ttemplate <class T> void setData(const T &t) // Used to transfer data from different tables/views having same data types and column names\n\t{" << std::endl;
1372-
for (auto c : columns)
1376+
for (auto& c : columns)
13731377
myfile << "\t\t" << c.first << " = t.get_" << c.first << "();" << std::endl;
13741378
myfile << "\t}" << std::endl;
13751379

@@ -1388,7 +1392,7 @@ namespace sqlite3pp
13881392
if (m_options.m.is_public_var_members != true)
13891393
myfile << ", which allows read-only access to protected member variables";
13901394
myfile << "." << std::endl;
1391-
for (auto c : columns)
1395+
for (auto& c : columns)
13921396
myfile << "\tconst " << c.second << "& get_" << c.first << "() const {return " << c.first << ";}" << std::endl;
13931397
}
13941398

@@ -1397,7 +1401,7 @@ namespace sqlite3pp
13971401
{
13981402
if (!m_options.m.exclude_comments)
13991403
myfile << "\n\t// A set_ function for each field in the table." << std::endl;
1400-
for (auto c : columns)
1404+
for (auto& c : columns)
14011405
myfile << "\tvoid set_" << c.first << "(const " << c.second << "& data__) {" << c.first << " = data__;}" << std::endl;
14021406
}
14031407

@@ -1407,10 +1411,10 @@ namespace sqlite3pp
14071411
const char* publicOrPrivate = m_options.m.is_public_var_members ? "public" : "protected";
14081412
myfile << publicOrPrivate << ":" << std::endl;
14091413
// Define data member variables associated with the table/view
1410-
for (auto c : columns)
1414+
for (auto& c : columns)
14111415
myfile << "\t" << c.second << " " << c.first << ";" << std::endl;
14121416

1413-
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";
1417+
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";
14141418
const char* OperatorStreamComment2 = "// sqlite3pp::TableOStream container interface.\n";
14151419
if (m_options.m.exclude_ostream_operator != true)
14161420
{
@@ -1420,7 +1424,7 @@ namespace sqlite3pp
14201424
// Create function OStream
14211425
myfile << "\ttemplate<class T> T& OStream(T& t) const\n\t{\n\t\tt.os";
14221426
std::string delimiter_tmp;
1423-
for (auto c : columns)
1427+
for (auto& c : columns)
14241428
{
14251429
if (IsStrType(c.second.c_str()))
14261430
myfile << delimiter_tmp << " << t.str(" << c.first << ")";
@@ -1435,7 +1439,7 @@ namespace sqlite3pp
14351439
myfile << "\tfriend std::ostream& operator<<(std::ostream& os, const " << ClassName << "& t);" << std::endl;
14361440
myfile << "\tfriend std::wostream& operator<<(std::wostream& os, const " << ClassName << "& t);" << std::endl;
14371441
// Create Delimit member function. It's needed for operator<<
1438-
myfile << "\tstatic StrType Delimiter() { return " << m_options.s.str_pre << " \"" << m_options.m.delimiter << "\" " << m_options.s.str_post << "; }" << std::endl;
1442+
myfile << "\tstatic StrType Delimiter() { return " << m_options.s.str_pre << "\"" << m_options.m.delimiter << "\" " << m_options.s.str_post << "; }" << std::endl;
14391443
if (!m_options.m.exclude_comments)
14401444
myfile << "\t" << CommentSection << std::endl;
14411445
}

0 commit comments

Comments
 (0)