Improvements to sqldb examples
Original Reporter info from Mantis: thierrybo
-
Reporter name:
Original Reporter info from Mantis: thierrybo
- Reporter name:
Description:
I updated the examples so that it works a little better "out of the box" :
- (cfilltable.pp, readme.txt): Added a comment to change the date format to suit the database used.
- (sqldbexampleunit.pp): Replaced "-" with DateSeparator to compile with all regional preferences.
- (database.ini): Added Oracle as a dbtype choice.
- (database.ini, alisttables.pp): Added Host parameter, it was not handled before, so the examples were working only with Interbase.
- (efilltableparams.pp): Added Mysql as a new case for FormatDateTime
Additional information:
Index: cfilltable.pp
===================================================================
--- cfilltable.pp (révision 15875)
+++ cfilltable.pp (copie de travail)
@@ -45,6 +45,8 @@
SQL.Add(' 1, ');
SQL.Add(' ''Florian Klaempfl'', ');
SQL.Add(' ''florian@freepascal.org'',');
+
+ // Please update the date format according to your database (ie. MySQL 1975-1-1)
SQL.Add(' ''1-jan-1975'' ');
SQL.Add(') ');
Index: sqldbexampleunit.pp
===================================================================
--- sqldbexampleunit.pp (révision 15875)
+++ sqldbexampleunit.pp (copie de travail)
@@ -20,6 +20,7 @@
mysql40conn, mysql41conn, mysql50conn, oracleconnection;
var dbtype,
+ dbhost,
dbname,
dbuser,
dbpassword : string;
@@ -69,19 +70,20 @@
begin
IniFile := TIniFile.Create('database.ini');
dbtype := IniFile.ReadString('Database','Type','');
+ dbhost := IniFile.ReadString('Database','Host','');
dbname := IniFile.ReadString('Database','Name','');
dbuser := IniFile.ReadString('Database','User','');
dbpassword := IniFile.ReadString('Database','Password','');
IniFile.Free;
- FPdevBirthDates[1] := StrToDate('1-1-1991');
- FPdevBirthDates[2] := StrToDate('2-2-1992');
- FPdevBirthDates[3] := StrToDate('3-3-1993');
- FPdevBirthDates[4] := StrToDate('4-4-1994');
- FPdevBirthDates[5] := StrToDate('5-5-1995');
- FPdevBirthDates[6] := StrToDate('6-6-1996');
- FPdevBirthDates[7] := StrToDate('7-7-1997');
- FPdevBirthDates[8] := StrToDate('8-8-1998');
+ FPdevBirthDates[1] := StrToDate('1'+DateSeparator+'1'+DateSeparator+'1991');
+ FPdevBirthDates[2] := StrToDate('2'+DateSeparator+'2'+DateSeparator+'1992');
+ FPdevBirthDates[3] := StrToDate('3'+DateSeparator+'3'+DateSeparator+'1993');
+ FPdevBirthDates[4] := StrToDate('4'+DateSeparator+'4'+DateSeparator+'1994');
+ FPdevBirthDates[5] := StrToDate('5'+DateSeparator+'5'+DateSeparator+'1995');
+ FPdevBirthDates[6] := StrToDate('6'+DateSeparator+'6'+DateSeparator+'1996');
+ FPdevBirthDates[7] := StrToDate('7'+DateSeparator+'7'+DateSeparator+'1997');
+ FPdevBirthDates[8] := StrToDate('8'+DateSeparator+'8'+DateSeparator+'1998');
end;
procedure CreateFConnection;
@@ -99,6 +101,7 @@
with Fconnection do
begin
+ HostName := dbhost;
DatabaseName := dbname;
UserName := dbuser;
Password := dbpassword;
Index: database.ini
===================================================================
--- database.ini (révision 15875)
+++ database.ini (copie de travail)
@@ -8,9 +8,15 @@
# * mysql50
# * odbc
# * postgresql
+# * oracle
type=interbase
+# host
+# gives the server name or IP that should be used. Leave blank if not used with
+# some databases (Interbase)
+host=127.0.0.1
+
# name
# gives the name of the database that should be used.
# This could be a file-name or an alias, dependent on which database-engine is
Index: alisttables.pp
===================================================================
--- alisttables.pp (révision 15875)
+++ alisttables.pp (copie de travail)
@@ -36,6 +36,7 @@
with Fconnection do
begin
+ HostName := dbhost;
DatabaseName := dbname;
UserName := dbuser;
Password := dbpassword;
Index: efilltableparams.pp
===================================================================
--- efilltableparams.pp (révision 15875)
+++ efilltableparams.pp (copie de travail)
@@ -46,16 +46,18 @@
for i := 5 to 7 do
begin
- if dbtype <> 'oracle' then
- sql[1] := 'values ('+inttostr(i)+ ', ' +
- '''' +FPdevNames[i]+ ''', ' +
- '''' +FPdevEmails[i]+ ''', ' +
- '''' +FormatDateTime('MM-DD-YYYY',FPdevBirthDates[i])+ ''')'
- else
- sql[1] := 'values ('+inttostr(i)+ ', ' +
- '''' +FPdevNames[i]+ ''', ' +
- '''' +FPdevEmails[i]+ ''', ' +
- '''' +FormatDateTime('DD-MMM-YYYY',FPdevBirthDates[i])+ ''')';
+ sql[1] := 'values ('+inttostr(i)+ ', ' +
+ '''' +FPdevNames[i]+ ''', ' +
+ '''' +FPdevEmails[i]+ ''', ';
+ if (LeftStr(dbtype, 5) = 'mysql') then
+ sql[1] := sql[1] + '''' + FormatDateTime('YYYY-MM-DD', FPdevBirthDates[i])
+ + ''')'
+ else if dbtype = 'oracle' then
+ sql[1] := sql[1] + '''' + FormatDateTime('DD-MMM-YYYY', FPdevBirthDates[i])
+ + ''')'
+ else
+ sql[1] := sql[1] + '''' + FormatDateTime('MM-DD-YYYY', FPdevBirthDates[i])
+ + ''')';
ExecSql;
end;
Index: readme.txt
===================================================================
--- readme.txt (révision 15875)
+++ readme.txt (copie de travail)
@@ -4,7 +4,8 @@
To use these examples you need a working login to a DB-Server and have the
appropiate client installed. You have to change 'database.ini' to work with the
-right database-engine and login-credentials.
+right database-engine and login-credentials. Also edit the date format according
+to your database in cfilltable.pp.
You can check if everything works fine by compiling & running 'alisttables'. If
everything works well, you'll get a list of all tables in the database provided
Mantis conversion info:
- Mantis ID: 17292
- Build: 15875
- Version: 2.5.1
- Fixed in revision: 18156 (#f20b5596)
- Monitored by: » thierrybo (thierrybo)