-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhk_firebirddatabase.cpp
195 lines (150 loc) · 5.05 KB
/
hk_firebirddatabase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// // ****************************************************************************
// copyright (c) 2000-2005 Horst Knorr <[email protected]>
// This file is part of the hk_firebirdclasses library.
// This file may be distributed and/or modified under the terms of the
// GNU Library Public License version 2 as published by the Free Software
// Foundation and appearing in the file COPYING included in the
// packaging of this file.
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// ****************************************************************************
#include "hk_firebirddatabase.h"
#include "hk_firebirdconnection.h"
#include "hk_firebirdtable.h"
#include "hk_firebirdresultquery.h"
#include "hk_firebirdview.h"
#include "hk_firebirdactionquery.h"
hk_firebirddatabase::hk_firebirddatabase(hk_firebirdconnection* c):hk_database(c)
{
#ifdef HK_DEBUG
// wanna_debug(true);
hkdebug("hk_firebirddatabase::hk_firebirddatabase");
#endif
p_firebirdconnection=c;
}
hk_firebirddatabase::~hk_firebirddatabase(void)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::~hk_firebirddatabase");
#endif
}
void hk_firebirddatabase::driver_specific_tablelist(void)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::driver_specific_tablelist");
#endif
p_tablelist.erase(p_tablelist.begin(),p_tablelist.end());
if (p_firebirdconnection!=NULL)
{
hk_string sql="select RDB$RELATION_NAME as \"tables\" from RDB$RELATIONS where RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR is NULL";
hk_datasource* ds=new_resultquery();
if (ds)
{
ds->set_sql(sql);
ds->enable();
hk_column* col=ds->column_by_name("tables");
if (col)
{
unsigned long m=ds->max_rows();
for (unsigned long i=0;i<m;i++)
{
p_tablelist.insert(p_tablelist.end(),trim(col->asstring()));
ds->goto_next();
}
}
else show_warningmessage("Error hk_firebirddatabase::driver_specific_tablelist, Systemcolumn could not be loaded");
delete ds;
}
//sort(p_tablelist.begin(),p_tablelist.end());
}
}
void hk_firebirddatabase::driver_specific_viewlist(void)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::driver_specific_viewlist");
#endif
p_viewlist.erase(p_viewlist.begin(),p_viewlist.end());
if (p_firebirdconnection!=NULL)
{
hk_string sql="select RDB$RELATION_NAME as \"views\" from RDB$RELATIONS where RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR is NOT NULL";
hk_datasource* ds=new_resultquery();
if (ds)
{
ds->set_sql(sql);
ds->enable();
hk_column* col=ds->column_by_name("views");
if (col)
{
unsigned long m=ds->max_rows();
for (unsigned long i=0;i<m;i++)
{
p_viewlist.insert(p_viewlist.end(),trim(col->asstring()));
ds->goto_next();
}
}
else show_warningmessage("Error hk_firebirddatabase::driver_specific_viewlist, Systemcolumn could not be loaded");
delete ds;
}
//sort(p_viewlist.begin(),p_viewlist.end());
}
}
bool hk_firebirddatabase::set_name(const hk_string& n)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::set_name");
#endif
hk_url url=n;
hk_string newname=n;
if (url.directory().size()==0 && p_firebirdconnection->defaultdatabase().size()>0)
{
hk_url defdburl=p_firebirdconnection->defaultdatabase();
if (defdburl.directory().size()>0) newname=defdburl.directory()+"/"+newname;
if (url.extension().size()==0)newname=newname+".fdb";
}
return hk_database::set_name(newname);
}
bool hk_firebirddatabase::driver_specific_select_db(void)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::driver_specific_select_db");
#endif
if (p_firebirdconnection!=NULL)
{
p_firebirdconnection->set_defaultdatabase(name());
p_firebirdconnection->driver_specific_disconnect();
return p_firebirdconnection->driver_specific_connect();
}
return false;
}
hk_datasource* hk_firebirddatabase::driver_specific_new_table(hk_presentation* p)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::driver_specific_new_table");
#endif
return new hk_firebirdtable(this,p);
}
hk_datasource* hk_firebirddatabase::driver_specific_new_resultquery(hk_presentation* p)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::driver_specific_resultquery");
#endif
return new hk_firebirdresultquery(this,p);
}
hk_datasource* hk_firebirddatabase::driver_specific_new_view(hk_presentation* p)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::driver_specific_new_view");
#endif
hk_firebirdview *x;
x = new hk_firebirdview(this , p);
return x ;
}
hk_actionquery * hk_firebirddatabase::driver_specific_new_actionquery(void)
{
#ifdef HK_DEBUG
hkdebug("hk_firebirddatabase::driver_specific_new_actionquery");
#endif
hk_firebirdactionquery *a;
a = new hk_firebirdactionquery(this);
return a;
}