2
The contents of this file are subject to the Initial Developer's Public
3
License Version 1.0 (the "License"); you may not use this file except in
4
compliance with the License. You may obtain a copy of the License here:
5
http://www.flamerobin.org/license.html.
7
Software distributed under the License is distributed on an "AS IS"
8
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9
License for the specific language governing rights and limitations under
12
The Original Code is FlameRobin (TM).
14
The Initial Developer of the Original Code is Milan Babuskov.
16
Portions created by the original developer
17
are Copyright (C) 2004 Milan Babuskov.
21
Contributor(s): Nando Dessena
24
//------------------------------------------------------------------------------
25
// For compilers that support precompilation, includes "wx/wx.h".
26
#include "wx/wxprec.h"
31
// for all others, include the necessary headers (this file is usually all you
32
// need because it includes almost all "standard" wxWindows headers
43
//------------------------------------------------------------------------------
48
infoLoadedM = false; // I had a 2 hour session with debugger to found out that this was missing
50
//------------------------------------------------------------------------------
51
bool YDomain::loadInfo()
53
IBPP::Database& db = getDatabase()->getDatabase();
57
IBPP::Transaction tr1 = IBPP::TransactionFactory(db, IBPP::amRead);
59
IBPP::Statement st1 = IBPP::StatementFactory(db, tr1);
61
"select t.rdb$type, f.rdb$field_sub_type, f.rdb$field_length,"
62
" f.rdb$field_precision, f.rdb$field_scale, c.rdb$character_set_name"
64
" join rdb$types t on f.rdb$field_type=t.rdb$type"
65
" left outer join rdb$character_sets c on c.rdb$character_set_id = f.rdb$character_set_id"
66
" where f.rdb$field_name = ?"
67
" and t.rdb$field_name='RDB$FIELD_TYPE'"
70
st1->Set(1, getName());
73
st1->Get(1, &datatypeM);
77
st1->Get(2, &subtypeM);
78
st1->Get(3, &lengthM);
82
st1->Get(4, &precisionM);
91
st1->Get(6, charsetM);
92
charsetM.erase(charsetM.find_last_not_of(" ")+1);
100
catch (IBPP::Exception &e)
102
lastError().setMessage(e.ErrorMessage());
106
lastError().setMessage("System error.");
110
//------------------------------------------------------------------------------
111
//! returns column's datatype as human readable string. It can also be used to construct DDL for tables
112
std::string YDomain::getDatatypeAsString()
117
std::ostringstream retval; // this will be returned
119
// special case (mess that some tools (ex. IBExpert) make by only setting scale and not changing type)
120
if (datatypeM == 27 && scaleM < 0)
122
retval << "Numeric(15," << -scaleM << ")";
126
// LONG&INT64: INT/SMALLINT (prec=0), DECIMAL(sub_type=2), NUMERIC(sub_type=1)
127
if (datatypeM == 7 || datatypeM == 8 || datatypeM == 16)
133
else if (datatypeM == 8)
136
return "Numeric(18,0)";
140
retval << (subtypeM == 2 ? "Decimal(" : "Numeric(");
141
if (precisionM <= 0 || precisionM > 18)
144
retval << precisionM;
145
retval << "," << -scaleM << ")";
150
std::string names[] = {
160
short mapper[8] = { 14, 10, 27, 35, 37, 261, 12, 13 };
162
for (int i=0; i<8; ++i)
164
if (mapper[i] == datatypeM)
171
if (datatypeM == 14 || datatypeM == 37) // char & varchar, add (length)
172
retval << "(" << lengthM << ")";
174
if (datatypeM == 261) // blob
175
retval << " sub_type " << subtypeM;
179
//------------------------------------------------------------------------------
180
void YDomain::getDatatypeParts(std::string& type, std::string& size, std::string& scale)
183
string datatype = getDatatypeAsString();
184
string::size_type p1 = datatype.find("(");
185
if (p1 != string::npos)
187
type = datatype.substr(0, p1);
188
string::size_type p2 = datatype.find(",");
189
if (p2 == string::npos)
190
p2 = datatype.find(")");
193
string::size_type p3 = datatype.find(")");
194
scale = datatype.substr(p2+1, p3-p2-1);
196
size = datatype.substr(p1+1, p2-p1-1);
201
//------------------------------------------------------------------------------
202
std::string YDomain::getCharset()
209
//------------------------------------------------------------------------------
210
std::string YDomain::getCreateSqlTemplate() const
212
return "CREATE DOMAIN domain_name\n"
214
"DEFAULT {literal | NULL | USER}\n"
216
"[CHECK (dom_search_condition)]\n"
217
"COLLATE collation;\n";
219
//------------------------------------------------------------------------------
220
const std::string YDomain::getTypeName() const
224
//------------------------------------------------------------------------------