1 |
tony |
45 |
unit Test1; |
2 |
tony |
56 |
{$IFDEF MSWINDOWS} |
3 |
|
|
{$DEFINE WINDOWS} |
4 |
|
|
{$ENDIF} |
5 |
tony |
45 |
|
6 |
|
|
{Create and Drop a Database} |
7 |
|
|
{ |
8 |
|
|
This test first attempts to create a database without specifying any parameters |
9 |
|
|
(should fail). It then goes on to create and drop a database, print out the |
10 |
|
|
parameters and then creates it again (will fail if the dropdatabase failed silently. |
11 |
|
|
|
12 |
|
|
Some basic database info is then accessed and printed. |
13 |
|
|
|
14 |
|
|
A basic query is performed and finally the database dropped. |
15 |
|
|
} |
16 |
|
|
|
17 |
tony |
56 |
{$IFDEF FPC} |
18 |
|
|
{$mode delphi} |
19 |
tony |
45 |
{$codepage utf8} |
20 |
tony |
56 |
{$ENDIF} |
21 |
tony |
45 |
|
22 |
|
|
interface |
23 |
|
|
|
24 |
|
|
uses |
25 |
|
|
Classes, SysUtils, TestManager, IB; |
26 |
|
|
|
27 |
|
|
type |
28 |
|
|
|
29 |
|
|
{ TTest1 } |
30 |
|
|
|
31 |
|
|
TTest1 = class(TTestBase) |
32 |
|
|
private |
33 |
|
|
procedure DoQuery(Attachment: IAttachment); |
34 |
|
|
public |
35 |
tony |
56 |
function TestTitle: AnsiString; override; |
36 |
|
|
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
37 |
tony |
45 |
end; |
38 |
|
|
|
39 |
|
|
implementation |
40 |
|
|
|
41 |
|
|
{ TTest1 } |
42 |
|
|
|
43 |
|
|
procedure TTest1.DoQuery(Attachment: IAttachment); |
44 |
|
|
var Transaction: ITransaction; |
45 |
|
|
Statement: IStatement; |
46 |
|
|
ResultSet: IResultSet; |
47 |
|
|
i: integer; |
48 |
|
|
begin |
49 |
|
|
Transaction := Attachment.StartTransaction([isc_tpb_read,isc_tpb_nowait,isc_tpb_concurrency],taCommit); |
50 |
|
|
Statement := Attachment.Prepare(Transaction,'Select * from RDB$Database',3); |
51 |
|
|
ResultSet := Statement.OpenCursor; |
52 |
|
|
ResultSet.SetRetainInterfaces(true); |
53 |
|
|
try |
54 |
|
|
while ResultSet.FetchNext do |
55 |
|
|
begin |
56 |
|
|
for i := 0 to ResultSet.getCount - 1 do |
57 |
|
|
writeln(OutFile,ResultSet[i].Name,' = ',ResultSet[i].AsString); |
58 |
|
|
end; |
59 |
|
|
finally |
60 |
|
|
ResultSet.Close; |
61 |
|
|
ResultSet.SetRetainInterfaces(false); |
62 |
|
|
end; |
63 |
|
|
end; |
64 |
|
|
|
65 |
tony |
56 |
function TTest1.TestTitle: AnsiString; |
66 |
tony |
45 |
begin |
67 |
|
|
Result := 'Test 1: Create and Drop a Database'; |
68 |
|
|
end; |
69 |
|
|
|
70 |
tony |
56 |
procedure TTest1.RunTest(CharSet: AnsiString; SQLDialect: integer); |
71 |
tony |
45 |
var DPB: IDPB; |
72 |
|
|
Attachment: IAttachment; |
73 |
tony |
56 |
createSQL: AnsiString; |
74 |
tony |
45 |
begin |
75 |
|
|
writeln(OutFile,'Creating a Database with empty parameters'); |
76 |
|
|
Attachment := FirebirdAPI.CreateDatabase('',nil,false); |
77 |
|
|
if Attachment = nil then |
78 |
|
|
writeln(OutFile,'Create Database fails (as expected): ',FirebirdAPI.GetStatus.GetMessage) |
79 |
|
|
else |
80 |
|
|
Attachment.DropDatabase; |
81 |
|
|
|
82 |
tony |
47 |
writeln(OutFile,'Creating a Database using an SQL Statement'); |
83 |
tony |
117 |
createSQL := Format('create database ''%s'' USER ''%s'' PASSWORD ''%s'' DEFAULT CHARACTER SET %s', |
84 |
tony |
47 |
[Owner.GetNewDatabaseName, Owner.GetUserName, Owner.GetPassword, CharSet]); |
85 |
|
|
Attachment := FirebirdAPI.CreateDatabase(createSQL,SQLDialect); |
86 |
|
|
WriteDBInfo(Attachment.GetDBInformation([isc_info_db_id,isc_info_db_SQL_Dialect])); |
87 |
tony |
117 |
writeln(outfile,'DB Connect String = ',Attachment.GetConnectString); |
88 |
|
|
writeln(outfile,'DB Charset ID = ',Attachment.GetDefaultCharSetID); |
89 |
|
|
writeln(outfile,'DB SQL Dialect = ',Attachment.GetSQLDialect); |
90 |
|
|
writeln(outfile,'DB Remote Protocol = ', Attachment.GetRemoteProtocol); |
91 |
|
|
writeln(outfile,'DB ODS Major Version = ',Attachment.GetODSMajorVersion); |
92 |
|
|
writeln(outfile,'DB ODS Minor Version = ',Attachment.GetODSMinorVersion); |
93 |
|
|
PrintDPB(Attachment.getDPB); |
94 |
tony |
47 |
|
95 |
tony |
117 |
{Demonstrate reconnect when database created with SQL Statement} |
96 |
|
|
Attachment.Disconnect; |
97 |
|
|
Attachment.Connect; |
98 |
|
|
|
99 |
tony |
47 |
writeln(OutFile,'Dropping Database'); |
100 |
|
|
if Attachment <> nil then |
101 |
|
|
Attachment.DropDatabase; |
102 |
|
|
|
103 |
tony |
45 |
writeln(OutFile,'Creating a Database with a DPD'); |
104 |
|
|
DPB := FirebirdAPI.AllocateDPB; |
105 |
|
|
DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName); |
106 |
|
|
DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword); |
107 |
|
|
DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet); |
108 |
|
|
DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect); |
109 |
|
|
|
110 |
|
|
Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB); |
111 |
|
|
|
112 |
tony |
117 |
writeln(outfile,'DB Connect String = ',Attachment.GetConnectString); |
113 |
|
|
writeln(outfile,'DB Charset ID = ',Attachment.GetDefaultCharSetID); |
114 |
|
|
writeln(outfile,'DB SQL Dialect = ',Attachment.GetSQLDialect); |
115 |
|
|
writeln(outfile,'DB Remote Protocol = ', Attachment.GetRemoteProtocol); |
116 |
|
|
writeln(outfile,'DB ODS Major Version = ',Attachment.GetODSMajorVersion); |
117 |
|
|
writeln(outfile,'DB ODS Minor Version = ',Attachment.GetODSMinorVersion); |
118 |
|
|
|
119 |
tony |
45 |
writeln(OutFile,'Dropping Database'); |
120 |
|
|
if Attachment <> nil then |
121 |
|
|
Attachment.DropDatabase; |
122 |
|
|
|
123 |
|
|
{Open Database} |
124 |
|
|
|
125 |
|
|
PrintDPB(DPB); |
126 |
|
|
writeln(OutFile,'Creating a Database with a DPD'); |
127 |
|
|
Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB); |
128 |
|
|
if Attachment = nil then |
129 |
|
|
begin |
130 |
|
|
writeln(OutFile,'Create Database Failed'); |
131 |
|
|
Exit; |
132 |
|
|
end; |
133 |
tony |
47 |
WriteDBInfo(Attachment.GetDBInformation([isc_info_db_id,isc_info_ods_version,isc_info_ods_minor_version])); |
134 |
tony |
117 |
writeln(outfile,'DB Connect String = ',Attachment.GetConnectString); |
135 |
|
|
writeln(outfile,'DB Charset ID = ',Attachment.GetDefaultCharSetID); |
136 |
|
|
writeln(outfile,'DB SQL Dialect = ',Attachment.GetSQLDialect); |
137 |
|
|
writeln(outfile,'DB Remote Protocol = ', Attachment.GetRemoteProtocol); |
138 |
|
|
writeln(outfile,'DB ODS Major Version = ',Attachment.GetODSMajorVersion); |
139 |
|
|
writeln(outfile,'DB ODS Minor Version = ',Attachment.GetODSMinorVersion); |
140 |
tony |
45 |
|
141 |
|
|
{Querying Database} |
142 |
|
|
DoQuery(Attachment); |
143 |
|
|
|
144 |
|
|
writeln(OutFile,'Dropping Database'); |
145 |
|
|
Attachment.DropDatabase; |
146 |
|
|
end; |
147 |
|
|
|
148 |
|
|
|
149 |
|
|
initialization |
150 |
|
|
RegisterTest(TTest1); |
151 |
|
|
|
152 |
|
|
end. |
153 |
|
|
|