1 |
|
unit Test1; |
2 |
+ |
{$IFDEF MSWINDOWS} |
3 |
+ |
{$DEFINE WINDOWS} |
4 |
+ |
{$IF defined(CompilerVersion) and (CompilerVersion >= 28)} |
5 |
+ |
{Delphi XE7 onwards}} |
6 |
+ |
{$define HASREQEX} |
7 |
+ |
{$IFEND} |
8 |
+ |
{$ENDIF} |
9 |
|
|
10 |
|
{Create and Drop a Database} |
11 |
|
{ |
18 |
|
A basic query is performed and finally the database dropped. |
19 |
|
} |
20 |
|
|
21 |
< |
{$mode objfpc}{$H+} |
21 |
> |
{$IFDEF FPC} |
22 |
> |
{$mode delphi} |
23 |
|
{$codepage utf8} |
24 |
+ |
{$define HASREQEX} |
25 |
+ |
{$ENDIF} |
26 |
|
|
27 |
|
interface |
28 |
|
|
37 |
|
private |
38 |
|
procedure DoQuery(Attachment: IAttachment); |
39 |
|
public |
40 |
< |
function TestTitle: string; override; |
41 |
< |
procedure RunTest(CharSet: string; SQLDialect: integer); override; |
40 |
> |
function TestTitle: AnsiString; override; |
41 |
> |
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
42 |
|
end; |
43 |
|
|
44 |
|
implementation |
67 |
|
end; |
68 |
|
end; |
69 |
|
|
70 |
< |
function TTest1.TestTitle: string; |
70 |
> |
function TTest1.TestTitle: AnsiString; |
71 |
|
begin |
72 |
|
Result := 'Test 1: Create and Drop a Database'; |
73 |
|
end; |
74 |
|
|
75 |
< |
procedure TTest1.RunTest(CharSet: string; SQLDialect: integer); |
75 |
> |
procedure TTest1.RunTest(CharSet: AnsiString; SQLDialect: integer); |
76 |
|
var DPB: IDPB; |
77 |
|
Attachment: IAttachment; |
78 |
< |
DBInfo: IDBInformation; |
69 |
< |
ConType: integer; |
70 |
< |
DBFileName: string; |
71 |
< |
DBSiteName: string; |
78 |
> |
createSQL: AnsiString; |
79 |
|
begin |
80 |
|
writeln(OutFile,'Creating a Database with empty parameters'); |
81 |
|
Attachment := FirebirdAPI.CreateDatabase('',nil,false); |
84 |
|
else |
85 |
|
Attachment.DropDatabase; |
86 |
|
|
87 |
+ |
writeln(OutFile,'Creating a Database using an SQL Statement'); |
88 |
+ |
createSQL := Format('create database ''%s'' USER ''%s'' PASSWORD ''%s'' DEFAULT CHARACTER SET %s', |
89 |
+ |
[Owner.GetNewDatabaseName, Owner.GetUserName, Owner.GetPassword, CharSet]); |
90 |
+ |
Attachment := FirebirdAPI.CreateDatabase(createSQL,SQLDialect); |
91 |
+ |
WriteDBInfo(Attachment.GetDBInformation([isc_info_db_id,isc_info_db_SQL_Dialect])); |
92 |
+ |
writeln(outfile,'DB Connect String = ',Attachment.GetConnectString); |
93 |
+ |
writeln(outfile,'DB Charset ID = ',Attachment.GetDefaultCharSetID); |
94 |
+ |
writeln(outfile,'DB SQL Dialect = ',Attachment.GetSQLDialect); |
95 |
+ |
writeln(outfile,'DB Remote Protocol = ', Attachment.GetRemoteProtocol); |
96 |
+ |
writeln(outfile,'DB ODS Major Version = ',Attachment.GetODSMajorVersion); |
97 |
+ |
writeln(outfile,'DB ODS Minor Version = ',Attachment.GetODSMinorVersion); |
98 |
+ |
PrintDPB(Attachment.getDPB); |
99 |
+ |
|
100 |
+ |
{$IFDEF HASREQEX} |
101 |
+ |
{Demonstrate reconnect when database created with SQL Statement} |
102 |
+ |
try |
103 |
+ |
Attachment.Disconnect; |
104 |
+ |
Attachment.Connect; |
105 |
+ |
except on E:Exception do |
106 |
+ |
writeln(OutFile,'Error reconnecting to Database: ',E.Message); |
107 |
+ |
end; |
108 |
+ |
{$ENDIF} |
109 |
+ |
|
110 |
+ |
writeln(OutFile,'Dropping Database'); |
111 |
+ |
if Attachment <> nil then |
112 |
+ |
Attachment.DropDatabase; |
113 |
+ |
|
114 |
|
writeln(OutFile,'Creating a Database with a DPD'); |
115 |
|
DPB := FirebirdAPI.AllocateDPB; |
116 |
|
DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName); |
120 |
|
|
121 |
|
Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB); |
122 |
|
|
123 |
+ |
writeln(outfile,'DB Connect String = ',Attachment.GetConnectString); |
124 |
+ |
writeln(outfile,'DB Charset ID = ',Attachment.GetDefaultCharSetID); |
125 |
+ |
writeln(outfile,'DB SQL Dialect = ',Attachment.GetSQLDialect); |
126 |
+ |
writeln(outfile,'DB Remote Protocol = ', Attachment.GetRemoteProtocol); |
127 |
+ |
writeln(outfile,'DB ODS Major Version = ',Attachment.GetODSMajorVersion); |
128 |
+ |
writeln(outfile,'DB ODS Minor Version = ',Attachment.GetODSMinorVersion); |
129 |
+ |
|
130 |
|
writeln(OutFile,'Dropping Database'); |
131 |
|
if Attachment <> nil then |
132 |
|
Attachment.DropDatabase; |
141 |
|
writeln(OutFile,'Create Database Failed'); |
142 |
|
Exit; |
143 |
|
end; |
144 |
< |
DBInfo := Attachment.GetDBInformation([isc_info_db_id]); |
145 |
< |
DBInfo[0].DecodeIDCluster(ConType,DBFileName,DBSiteName); |
146 |
< |
writeln(OutFile,'Database ID = ', ConType,' FB = ', DBFileName, ' SN = ',DBSiteName); |
147 |
< |
DBInfo := Attachment.GetDBInformation([isc_info_ods_version]); |
148 |
< |
write(OutFile,'ODS major = ',DBInfo[0].getAsInteger); |
149 |
< |
DBInfo := Attachment.GetDBInformation([isc_info_ods_minor_version]); |
150 |
< |
writeln(OutFile,' minor = ', DBInfo[0].getAsInteger ); |
144 |
> |
WriteDBInfo(Attachment.GetDBInformation([isc_info_db_id,isc_info_ods_version,isc_info_ods_minor_version])); |
145 |
> |
writeln(outfile,'DB Connect String = ',Attachment.GetConnectString); |
146 |
> |
writeln(outfile,'DB Charset ID = ',Attachment.GetDefaultCharSetID); |
147 |
> |
writeln(outfile,'DB SQL Dialect = ',Attachment.GetSQLDialect); |
148 |
> |
writeln(outfile,'DB Remote Protocol = ', Attachment.GetRemoteProtocol); |
149 |
> |
writeln(outfile,'DB ODS Major Version = ',Attachment.GetODSMajorVersion); |
150 |
> |
writeln(outfile,'DB ODS Minor Version = ',Attachment.GetODSMinorVersion); |
151 |
|
|
152 |
|
{Querying Database} |
153 |
|
DoQuery(Attachment); |