Skip to content

Commit

Permalink
Moved Table Arg types out side of the class
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Maisonave committed Dec 1, 2021
1 parent 093d4c0 commit 6e8521f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 59 deletions.
2 changes: 1 addition & 1 deletion sqlite3pp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ namespace sqlite3pp
return *this;
}

query::query_iterator::value_type query::query_iterator::operator*() const
query::rows query::query_iterator::operator*() const
{
return rows(cmd_->stmt_);
}
Expand Down
2 changes: 1 addition & 1 deletion sqlite3pp.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ namespace sqlite3pp
query_iterator& operator++();

//#pragma warning(disable : 4996)
sqlite3pp::query::rows operator*() const;
query::rows operator*() const;

private:
query* cmd_;
Expand Down
58 changes: 36 additions & 22 deletions sqlite3pp_ez.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ namespace sqlite3pp
bool sql_base::bIsGlblDbOpen = false;
const char sql_base::TableArg_PreExecuteArg[] = "PreExecuteArg";
const char sql_base::TableArg_WhereClauseArg[] = "WhereClauseArg";
const char sql_base::TableArg_InsertArg[] = "InsertArg";
const char sql_base::TableArg_DbFileNameArg[] = "DbFileNameArg";
const char sql_base::TableArg_ValueArg[] = "ValueArg";

Expand Down Expand Up @@ -353,7 +352,7 @@ namespace sqlite3pp
{
if (strcmp("INTEGER", str) == 0 || strcmp("INT", str) == 0 || strcmp("TINYINT", str) == 0 || strcmp("SMALLINT", str) == 0 || strcmp("MEDIUMINTSMALLINT", str) == 0 || strcmp("BIGINT", str) == 0 || strcmp("UNSIGNED BIG INT", str) == 0 || strcmp("INT2", str) == 0 || strcmp("INT8", str) == 0)
return "int";
if (strcmp("REAL", str) == 0 || strcmp("DOUBLE", str) == 0 || strcmp("DOUBLE PRECISION", str) == 0 || strcmp("FLOAT", str) == 0 || strncmp("DECIMAL", str, 7) == 0 || strcmp("BOOLEAN", str) == 0 || strcmp("DATE", str) == 0 || strcmp("DATETIME", str) == 0 || strcmp("NUMERIC", str) == 0)
if (strcmp("REAL", str) == 0 || strcmp("DOUBLE", str) == 0 || strcmp("DOUBLE PRECISION", str) == 0 || strcmp("FLOAT", str) == 0 || strncmp("DECIMAL", str, 7) == 0 || strcmp("BOOLEANL", str) == 0 || strcmp("BOOLEAN", str) == 0 || strcmp("DATE", str) == 0 || strcmp("DATETIME", str) == 0 || strcmp("NUMERIC", str) == 0)
return "double";

if (m_options.m.use_basic_types_only)
Expand Down Expand Up @@ -381,7 +380,7 @@ namespace sqlite3pp
return "Smallint";
if (strcmp("MEDIUMINTSMALLINT", str) == 0)
return "Mediumint";
if (strcmp("BOOLEAN", str) == 0)
if (strcmp("BOOLEAN", str) == 0 || strcmp("BOOLEANL", str) == 0)
return "Boolean";
if (strcmp("BIGINT", str) == 0)
return "Bigint";
Expand Down Expand Up @@ -436,10 +435,10 @@ namespace sqlite3pp
return option;
}

void SQLiteClassBuilder::Init(const std::string & TableOrView_name, const std::string & WhereClause)
void SQLiteClassBuilder::Init(const std::string & TableOrView_name, const std::string & AndWhereClause)
{
if (TableOrView_name == CreateHeaderForAllTables)
CreateAllHeaders(m_options, WhereClause);
CreateAllHeaders(m_options, AndWhereClause);
else if (!TableOrView_name.empty() && TableOrView_name != Nill)
CreateHeader(TableOrView_name);
}
Expand All @@ -449,9 +448,9 @@ namespace sqlite3pp
m_db.disconnect();
}

bool SQLiteClassBuilder::CreateAllHeaders(const std::string &WhereClause)
bool SQLiteClassBuilder::CreateAllHeaders(const std::string &AndWhereClause)
{
return CreateAllHeaders(m_options, WhereClause);
return CreateAllHeaders(m_options, AndWhereClause);
}
static const char TopHeaderCommnetsPrt1[] = "/* This file was automatically generated using [Sqlite3pp_EZ].\nSqlite3pp_EZ Copyright (C) 2021 David Maisonave (http::\\www.axter.com)";
static const char TopHeaderCommnetsPrt2[] = "For more details see https://github.com/David-Maisonave/sqlite3pp_EZ\n*/";
Expand Down Expand Up @@ -494,14 +493,14 @@ namespace sqlite3pp
return true;
}

bool SQLiteClassBuilder::CreateAllHeaders(const TblClassOptions &strtype, const std::string &WhereClause)
bool SQLiteClassBuilder::CreateAllHeaders(const TblClassOptions &strtype, const std::string &AndWhereClause)
{
m_HeadersCreated.clear();
m_ClassNames.clear();
m_options = strtype;
const std::string OrgPrefix = m_options.h.header_prefix;
using SQLiteMaster = Table<sqlite_master>;
SQLiteMaster tbl(m_db, SQLiteMaster::WhereClauseArg("where (type = 'table' or type = 'view') " + WhereClause));
SQLiteMaster tbl(m_db, WhereClauseArg(T_("where (type = 'table' or type = 'view') ") + sql_base::to_tstring(AndWhereClause)) );
for (auto t : tbl)
{
m_options.h.header_prefix = OrgPrefix + t.type + "_";
Expand Down Expand Up @@ -741,26 +740,41 @@ namespace sqlite3pp

std::wstring query::rows::get(int idx, const std::wstring&) const
{
#ifdef SQLITE3PP_ALLOW_NULL_STRING_RETURN
bool AllowNullStringReturn = true;
#else
bool AllowNullStringReturn = false;
#endif // !SQLITE3PP_ALLOW_NULL_STRING_RETURN
std::wstring value;
const char * strtype = sqlite3_column_decltype(stmt_, idx);
wchar_t const* Val = get(idx, (wchar_t const*)0);
#ifndef SQLITE3PP_ALLOW_NULL_STRING_RETURN
if (!Val)
return value;
#endif // !SQLITE3PP_ALLOW_NULL_STRING_RETURN
bool GetUnicodeString = false;
if (!strtype || strcmp(strtype, "TEXT") == 0 || strncmp("CHARACTER", strtype, 9) == 0 || strncmp("VARYING CHARACTER", strtype, 17) == 0 || strncmp("VARCHAR", strtype, 7) == 0)
GetUnicodeString = false;
else if ( strncmp("NCHAR", strtype, 5) == 0 || strncmp("NVARCHAR", strtype, 8) == 0 || strncmp("NATIVE CHARACTER", strtype, 16) == 0)
GetUnicodeString = true;
else
{
assert(0);// Code should NOT get here. If it does something went wrong.
GetUnicodeString = false;
}

if (!strtype)
union
{ // This union is here for debugging purposes.
wchar_t const* Val_w;
char const* Val_a;
const void* Val;
};
if (GetUnicodeString)
{
value = sql_base::to_wstring((char*)(Val));
Val_w = get(idx, (wchar_t const*)0);
if (Val_w || AllowNullStringReturn)
value = Val_w;
}
else if (strcmp(strtype, "TEXT") == 0 || strncmp("CHARACTER", strtype, 9) == 0 || strncmp("VARYING CHARACTER", strtype, 17) == 0 || strncmp("VARCHAR", strtype, 7) == 0)
value = sql_base::to_wstring((char*)(Val));
else if ( strncmp("NCHAR", strtype, 5) == 0 || strncmp("NVARCHAR", strtype, 8) == 0 || strncmp("NATIVE CHARACTER", strtype, 16) == 0)
value = Val;
else
{
assert(0);// Code should NOT get here. If it does something went wrong.
value = sql_base::to_wstring((char*)(Val)); // Handle it gracefully in release mode.
Val_a = get(idx, (char const*)0);
if (Val_a || AllowNullStringReturn)
value = sql_base::to_wstring(Val_a);
}

return value;
Expand Down
Loading

0 comments on commit 6e8521f

Please sign in to comment.