forked from hgourvest/uib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Help.htm
239 lines (232 loc) · 12.8 KB
/
Help.htm
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title></title><meta name="vs_showGrid" content="False">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<h2>Installing UIB</h2>
<p>UIB need <strong>SYNEDIT</strong> components with Delphi, Kylix and BCB, this
package is used by the SQL property editor. <a href="http://prdownloads.sourceforge.net/synedit/synedit-cvs-2004-10-09.zip?download">
Download</a> and install this package.</p>
<ul>
<li>
Installing UIB with Delphi.
<ul>
<li>
Add the UIB library path in the Delphi Environment Options, ex: "<font color="#000099">C:\UIB\source".</font>
</li><li>
Open and <u>compile</u> the runtime package: UIBD<font color="#ff0033">X</font>R.dpk.
</li><li>
Open and <u>install </u>the design pakage: UIBD<font color="#ff0033">X</font>D.dpk</li></ul>
</li><li>
Installing UIB with BC++ Builder.
<ul>
<li>
Open and <u>compile</u> the runtime package: UIBC<font color="#ff0033">X</font>R.bpk.
</li><li>
Design packages are preconfigured to use SYNEDIT in this path: <font color="#000099">
"$(BCB)\Source\synedit\Source</font>". Change this path if needed.
</li><li>
Open and <u>install </u>the design pakage: UIBC<font color="#ff0033">X</font>D.bpk</li></ul>
</li><li>
Installing UIB with Kylix.
<ul>
<li>
Install UIBPack_K3.dpk.</li></ul>
</li><li>
Installing UIB on Lazarus.
<ul>
<li>
Install the package named "uiblaz.lpk" in the source directory.
</li><li>
Finally rebuild Lazarus IDE because lazarus link packages statically (Tool >
Build Lazarus).</li></ul>
</li>
</ul>
<h2>Using TUIBQuery </h2>
<p style="margin-right: 0px;" dir="ltr">There is 3 methods to use this component.</p>
<ul>
<li dir="ltr">
<h3>Open (Allocate statement + Prepare + Execute + Fetch)</h3>
Typically used for SELECT statements.<br>
You can't use the QuickScript property with this method.<br>
<strong>Note</strong> : <em>If you need to open the same query again but with
different
<br>
parametters don't Close the query and Open the query
<br>
again, it will be <u>faster</u> because the query will not be prepared
each time.</em>
<br>
<pre> <br> Query.SQL.Text := <font color="#333399">'SELECT FIRST_NAME, LAST_NAME, SALARY FROM EMPLOYEE WHERE DEPT_NO = :Num'</font>;<br> Query.Params.ByNameAsInteger[<font color="#333399">'Num'</font>] := 623;<br> Query.<font color="#ff0066">Open</font>;<br> <strong>while</strong> <strong>not</strong> Query.EOF <strong>do</strong>
<strong>with</strong> Query, Fields <strong>do</strong>
<strong>begin</strong>
memo.Lines.Add(format(<font color="#333399">'%s %s, Salary: %f'</font>
,
[ByNameAsString[<font color="#333399">'FIRST_NAME'</font>],<br> ByNameAsString[<font color="#333399">'LAST_NAME'</font>],<br> ByNameAsCurrency[<font color="#333399">'SALARY'</font>]]));<br> Next;<br> <strong>end</strong>;<br> Query.Close(etmCommit); <br> </pre>
</li>
</ul>
<ul>
<li dir="ltr">
<h3>Execute (Allocate statement + Pepare + Execute)</h3>
Typically used for "Data Pump". It is the fastest way to execute the same<br>
operation many times without having to prepare the query for each operation.<br>
You can't use the QuickScript property with this method.
<pre><strong>const</strong>
Datas : <strong>array</strong>[1..10] <strong>of</strong> TARecord = (<br> (COUNTRY: 'blabla0'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla1'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla2'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla3'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla4'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla5'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla6'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla7'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla8'; CURRENCY: 'blabla'),<br> (COUNTRY: 'blabla9'; CURRENCY: 'blabla'));<br><strong>begin</strong>
<strong>for</strong> i := 1 <strong>to</strong> 10 <strong>do</strong>
<strong>begin</strong>
Query.Params.AsString[0] := Datas[i].COUNTRY;
Query.Params.AsString[1] := Datas[i].CURRENCY;
Query.<font color="#ff0066">Execute</font>;<br><font color="#333399"> // for better performance commit every 1000 records <br>// if i mod 1000 = 0 then Transaction.Commit;</font>
<strong>end</strong>;<br> Query.Close(etmRollback); <font color="#333399">// change to etmCommit to apply.</font>
<strong>end</strong>;<br></pre>
</li>
</ul>
<ul>
<li dir="ltr">
<h3 style="margin-right: 0px;">ExecSQL (Execute Immediate)</h3>
The fastest way to execute many differents SQL statements like a script.<br>
Setting the QuickScript property to True you must have <u>one SQL statement</u>
<br>
<u>per line</u>. This method can use parammetters but can't return results.
<pre> Query.QuickScript := True;<br> Query.SQL.Add(<font color="#333399">'INSERT INTO COUNTRY (COUNTRY,CURRENCY) VALUES (''Test0'',''FFranc'')'</font>);<br> Query.SQL.Add(<font color="#333399">'DELETE FROM COUNTRY WHERE COUNTRY = ''Test0'''</font>);<br> .../...<br> Query.<font color="#ff3366">ExecSQL</font>;<br> Query.Close(etmCommit);<br> </pre>
</li>
</ul>
<h2 align="left">Transaction Rules</h2>
<blockquote style="margin-right: 0px;" dir="ltr">
<h3>Definitions:</h3>
<ul>
<li>
<u>Commit</u>:<em> apply changes and close transaction.</em>
</li><li>
<u>Rollback</u>: <em>cancel changes and close transaction</em>.
</li><li>
<u>CommitRetaining</u>: <em>apply changes and keep the transaction open</em>.
</li><li>
<u>RollbackRetaining</u>: <em>cancel changes and keep transaction open.</em></li></ul>
<h3>Rules</h3>
<ol>
<li>
Transactions are started automaticaly when a Query is Open.
</li><li>
Transactions stay alive until all attached queries are closed if
AutoRetain = True.
</li><li>
Transaction rollbacked automatically on internal error (open, ExecSQL, next
...).
</li><li>
Transaction commited automatically if a query component is destroyed or
detached from transaction.</li></ol>
<h3>Example</h3>
<pre><strong>procedure</strong> TForm1.BtOpenClick(Sender: TObject);<br><strong>var</strong>
Transaction: TUIBTransaction;
Query1: TUIBQuery;
Query2: TUIBQuery;
<strong>begin</strong>
Transaction := TUIBTransaction.Create(<strong>nil</strong>);<br> Query1 := TUIBQuery.Create(<strong>nil</strong>);<br> Query2 := TUIBQuery.Create(<strong>nil</strong>);<br> <strong>try</strong>
Transaction.DataBase := DataBase;
Query1.Transaction := Transaction;
Query2.Transaction := Transaction;
<strong>try</strong>
Query1.SQL.Text := <font color="#333399">'SELECT * FROM MYTABLE1</font>;<br> Query1.Open; <font color="#666699"><font color="#333399">// transaction </font><font color="#ff0066">started </font><font color="#333399">(Rule 1)</font>
</font> <strong>while</strong> <strong>not</strong> Query1.Eof <strong>do</strong>
<strong>begin</strong>
<font color="#333399">// ...<br></font> Query1.Next;<br> <strong>end;</strong>
Query1.Close; <font color="#333399">// <font color="#ff0066">Stay in</font> transaction (default action)</font>
Query2.SQL.Text := <font color="#333399">'SELECT * FROM MYTABLE2'</font>;<br> Query2.Open; <font color="#333399">// transaction not started because Query1 have not closed the Transaction.</font>
<font color="#333399">// On <font color="#ff0066">error</font> the transaction is automatically </font><font color="#ff0066">rollbacked</font><font color="#333399">(Rule 3)</font>
<strong>while</strong> <strong>not</strong> Query1.Eof <strong>do</strong>
<strong>begin</strong>
<font color="#333399">// ...</font>
Query2.Next;
<strong>end</strong>;<br> Query2.Close(etmCommit); <font color="#333399">// Transaction <font color="#ff0066">Commited</font> because Query1 is closed</font>
<font color="#333399">// if Query1 not closed and AutoRetain = True, then <font color="#ff0066">CommitRetaining</font><font color="#333399">(Rule 2)</font>
</font>
<strong>except</strong>
Transaction.RollBack; <font color="#333399">// on <font color="#ff0066">error</font> transaction </font><font color="#ff0066">rollbacked</font>
<font color="#333399">// ...</font>
<strong>end</strong>;<br> <strong>finally</strong>
Query1.Free; <font color="#333399">// if transaction active then close & </font><font color="#ff0066">commit</font><font color="#333399">(Rule 4)</font>
Query2.Free; <font color="#333399">// if transaction active then close & </font><font color="#ff0066">commit</font><font color="#333399">(Rule 4)</font>
Transaction.Free;
<strong>end</strong>;<br><strong>end;</strong>
</pre>
</blockquote>
<p> </p>
<h2 align="left">Compiler Options</h2>
<p align="left">First of all you have to set some compiler options depending which
type of application you are writing and which database you are using.<br>
Edit the "UIB.inc" file in the source directory with a text editor and
uncomment compiler options you need.</p>
<blockquote style="margin-right: 0px;" dir="ltr">
<h3 align="left">Database.</h3>
<blockquote>
<h4 align="left">Borland Interbase</h4>
<ul>
<li>
<div align="left">Interbase 6.0x, you don't need to set anything, you can work with
any database version.</div>
</li><li>
<div align="left">Interbase 6.5, <font color="#336600">{$DEFINE IB65}</font></div>
</li><li>
<div align="left">Interbase 7, <font color="#336600">{$DEFINE IB7}</font></div>
</li>
</ul>
<h4 align="left">Filrebird</h4>
<ul>
<li>
<div align="left">Firebird 1.02, <font color="#336600">{$DEFINE FB102}</font></div>
</li><li>
<div align="left">
<div align="left">Firebird 1.03, <font color="#336600">{$DEFINE FB103}</font></div>
</div>
</li><li>
<div align="left">
<div align="left">Firebird 1.5, <font color="#336600">{$DEFINE FB15}</font></div>
</div>
</li><li>Firebird 2, <font color="#336600">{$DEFINE FB20}</font></li>
</ul></blockquote>
<h3 align="left">Multithreading and N-Tiers servers application.</h3>
<blockquote style="margin-right: 0px;" dir="ltr">
<p align="left">You have 2 choices:</p>
<p align="left"><u>Sharing one DB connection with all threads</u>, in this
case 2 threads can share the same Database connection or the
same Transaction safely without freezing the server. Some examples of
server applications are: Web server, CORBA, DCOM, or Delphi ORB provided
provided with UIB. For an example of Multithread server try the the sample
applications in the "ClentServer" directory. You must set this compiler
option: <font color="#336600">{$DEFINE UIBTHREADSAFE}</font> excepting with
Interbase 7 (The library is allready ThreadSafe)</p>
</blockquote><blockquote style="margin-right: 0px;" dir="ltr">
<p><u>Create one DB Connection per Thread</u>, in this case you should desactivate <font color="#336600">
{$DEFINE UIBTHREADSAFE}</font>, and setting your DB connection to use the
remote protocol (excepting with Interbase 7), to have all threads working
faster.</p>
</blockquote>
<h3>Borland C++ Builder 6</h3>
<blockquote style="margin-right: 0px;" dir="ltr">
<p>You can choose to use original Interbase header files (IBase.h & IBError.h)
in this case uncomment <font color="#336600">{$DEFINE USE_IBERROR_H}</font> &
<font color="#336600">{$DEFINE USE_IBASE_H}</font>.</p>
</blockquote>
<h3 align="left">Languages
</h3>
<ul style="margin-right: 0px;" dir="ltr">
<li>
<div><font color="#336600">{$DEFINE UIBLANG_EN}</font>: English language. (Default)</div>
</li><li>
<div>
<div><font color="#336600">{$DEFINE UIBLANG_DE}</font>: Deutch language.</div>
</div>
</li><li>
<div><font color="#336600">{$DEFINE UIBLANG_FR}</font>: French language. </div>
</li><li>
<div>
<div><font color="#336600">{$DEFINE UIBLANG_CZ}</font>: Czech
language. </div>
</div>
</li>
</ul>
<h3>Lazarus & FPC</h3><p> </p>
</blockquote>
</body></html>