mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-07 22:03:42 -06:00
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
This commit is contained in:
parent
6a6ae049ed
commit
35e44db9eb
2 changed files with 103 additions and 96 deletions
|
|
@ -1,95 +1,99 @@
|
|||
#include "Sql.h"
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
static String sPutId(const char *type, Index<String>& 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<String> tab = session.EnumTables(database);
|
||||
Index<String> id;
|
||||
for(int i = 0; i < tab.GetCount(); i++) {
|
||||
r << sPutId("TABLE", id, tab[i]) << ")\r\n";
|
||||
Vector<SqlColumnInfo> 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<String>& 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<String> tab = session.EnumTables(database);
|
||||
Index<String> done;
|
||||
for(int i = 0; i < tab.GetCount(); i++) {
|
||||
sId(r, tab[i], done);
|
||||
Vector<SqlColumnInfo> 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<String>& 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<String> tab = session.EnumTables(database);
|
||||
Index<String> id;
|
||||
for(int i = 0; i < tab.GetCount(); i++) {
|
||||
r << sPutId("TABLE", id, tab[i]) << ")\r\n";
|
||||
Vector<SqlColumnInfo> 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<String>& 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<String> tab = session.EnumTables(database);
|
||||
Index<String> done;
|
||||
for(int i = 0; i < tab.GetCount(); i++) {
|
||||
sId(r, tab[i], done);
|
||||
Vector<SqlColumnInfo> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue