From 35e44db9ebe185eb1cc42e5323e9f4d8912acaa2 Mon Sep 17 00:00:00 2001 From: rylek Date: Fri, 29 Aug 2008 15:07:26 +0000 Subject: [PATCH] NOAPPSQL fixes for the third time (TRC, don't know why it keeps syncing that) git-svn-id: svn://ultimatepp.org/upp/trunk@385 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Sql/ExportSch.cpp | 194 ++++++++++++++++++++------------------- uppsrc/Sql/SqlSchema.h | 5 +- 2 files changed, 103 insertions(+), 96 deletions(-) diff --git a/uppsrc/Sql/ExportSch.cpp b/uppsrc/Sql/ExportSch.cpp index f2fc4a0c1..0fb091c25 100644 --- a/uppsrc/Sql/ExportSch.cpp +++ b/uppsrc/Sql/ExportSch.cpp @@ -1,95 +1,99 @@ -#include "Sql.h" - -NAMESPACE_UPP - -static String sPutId(const char *type, Index& id, String n, int w = 0) -{ - String r = type; - if(id.Find(n) < 0) { - id.Add(n); - r << '_'; - } - r << String(' ', max(0, w - r.GetLength())) << '(' << n; - return r; -} - -String ExportSch(SqlSession& session, const String& database) -{ - String r; - Vector tab = session.EnumTables(database); - Index id; - for(int i = 0; i < tab.GetCount(); i++) { - r << sPutId("TABLE", id, tab[i]) << ")\r\n"; - Vector c = session.EnumColumns(database, tab[i]); - for(int i = 0; i < c.GetCount(); i++) { - String type; - int width = Null; - switch(c[i].type) { - case INT_V: - type = "INT"; - break; - case DOUBLE_V: - type = "DOUBLE"; - break; - case DATE_V: - type = "DATE"; - break; - case TIME_V: - type = "TIME"; - break; - case STRING_V: - type = "STRING"; - width = c[i].width; - break; - default: - type = "STRING"; - width = 200; - break; - } - r << '\t' << sPutId(type, id, c[i].name, 8); - if(width > 0 && width < 40000) - r << ", " << width; - r << ")\r\n"; - } - r << "END_TABLE\r\n\r\n"; - } - return r; -} - -String ExportSch(const String& database) -{ - return ExportSch(SQL.GetSession(), database); -} - -static void sId(String& r, const String& id, Index& done) -{ - String u = ToUpper(id); - if(done.Find(u) >= 0) - return; - done.Add(u); - if(u == id) - r << "SQLID(" << id << ")\r\n"; - else - r << "SQL_ID(" << u << ", " << id << ")\r\n"; -} - -String ExportIds(SqlSession& session, const String& database) -{ - String r; - Vector tab = session.EnumTables(database); - Index done; - for(int i = 0; i < tab.GetCount(); i++) { - sId(r, tab[i], done); - Vector c = session.EnumColumns(database, tab[i]); - for(int i = 0; i < c.GetCount(); i++) - sId(r, c[i].name, done); - } - return r; -} - -String ExportIds(const String& database) -{ - return ExportIds(SQL.GetSession(), database); -} - -END_UPP_NAMESPACE +#include "Sql.h" + +NAMESPACE_UPP + +static String sPutId(const char *type, Index& id, String n, int w = 0) +{ + String r = type; + if(id.Find(n) < 0) { + id.Add(n); + r << '_'; + } + r << String(' ', max(0, w - r.GetLength())) << '(' << n; + return r; +} + +String ExportSch(SqlSession& session, const String& database) +{ + String r; + Vector tab = session.EnumTables(database); + Index id; + for(int i = 0; i < tab.GetCount(); i++) { + r << sPutId("TABLE", id, tab[i]) << ")\r\n"; + Vector c = session.EnumColumns(database, tab[i]); + for(int i = 0; i < c.GetCount(); i++) { + String type; + int width = Null; + switch(c[i].type) { + case INT_V: + type = "INT"; + break; + case DOUBLE_V: + type = "DOUBLE"; + break; + case DATE_V: + type = "DATE"; + break; + case TIME_V: + type = "TIME"; + break; + case STRING_V: + type = "STRING"; + width = c[i].width; + break; + default: + type = "STRING"; + width = 200; + break; + } + r << '\t' << sPutId(type, id, c[i].name, 8); + if(width > 0 && width < 40000) + r << ", " << width; + r << ")\r\n"; + } + r << "END_TABLE\r\n\r\n"; + } + return r; +} + +#ifndef NOAPPSQL +String ExportSch(const String& database) +{ + return ExportSch(SQL.GetSession(), database); +} +#endif + +static void sId(String& r, const String& id, Index& done) +{ + String u = ToUpper(id); + if(done.Find(u) >= 0) + return; + done.Add(u); + if(u == id) + r << "SQLID(" << id << ")\r\n"; + else + r << "SQL_ID(" << u << ", " << id << ")\r\n"; +} + +String ExportIds(SqlSession& session, const String& database) +{ + String r; + Vector tab = session.EnumTables(database); + Index done; + for(int i = 0; i < tab.GetCount(); i++) { + sId(r, tab[i], done); + Vector c = session.EnumColumns(database, tab[i]); + for(int i = 0; i < c.GetCount(); i++) + sId(r, c[i].name, done); + } + return r; +} + +#ifndef NOAPPSQL +String ExportIds(const String& database) +{ + return ExportIds(SQL.GetSession(), database); +} +#endif + +END_UPP_NAMESPACE diff --git a/uppsrc/Sql/SqlSchema.h b/uppsrc/Sql/SqlSchema.h index 12b5dbb6c..ed85cebe0 100644 --- a/uppsrc/Sql/SqlSchema.h +++ b/uppsrc/Sql/SqlSchema.h @@ -109,6 +109,9 @@ inline void SqlSchemaClear(T *a, int n) { } String ExportSch(SqlSession& session, const String& database); -String ExportSch(const String& database); String ExportIds(SqlSession& session, const String& database); + +#ifndef NOAPPSQL +String ExportSch(const String& database); String ExportIds(const String& database); +#endif