Browse Source

* Most sqldb example fixes from Mantis #17292.

git-svn-id: trunk@18156 -
marco 14 years ago
parent
commit
f20b559668

+ 6 - 4
packages/fcl-db/src/sqldb/examples/alisttables.pp

@@ -36,10 +36,12 @@ begin
 
   with Fconnection do
     begin
-    DatabaseName := dbname;
-    UserName := dbuser;
-    Password := dbpassword;
-    open;
+      if dbhost<>'' then
+        hostname:=dbhost;
+      DatabaseName := dbname;
+      UserName := dbuser;
+      Password := dbpassword;
+      open;
     end;
 
 // create FTransaction

+ 1 - 0
packages/fcl-db/src/sqldb/examples/cfilltable.pp

@@ -45,6 +45,7 @@ begin
     SQL.Add('  1,                         ');
     SQL.Add('  ''Florian Klaempfl'',      ');
     SQL.Add('  ''[email protected]'',');
+// Please update the date format according to your database (ie. MySQL 1975-1-1)
     SQL.Add('  ''1-jan-1975''               ');
     SQL.Add(')                            ');
 

+ 6 - 0
packages/fcl-db/src/sqldb/examples/database.ini

@@ -11,6 +11,12 @@
 
 type=interbase
 
+# host
+# gives optionally the server name or IP that should be used. 
+# do not specify 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

+ 3 - 2
packages/fcl-db/src/sqldb/examples/readme.txt

@@ -3,8 +3,9 @@ In this directory you can find some examples for SQLdb. They can also be used
 to test functionality and new connections.
 
 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.
+appropiate client installed.  You have to change 'database.ini' to work with
+the right database-engine and login-credentials.  Also check if the format
+of various dates matches the format your db expects.
 
 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

+ 7 - 9
packages/fcl-db/src/sqldb/examples/sqldbexampleunit.pp

@@ -22,6 +22,7 @@ uses
 var dbtype,
     dbname,
     dbuser,
+    dbhost,
     dbpassword   : string;
 
     Fconnection  : tSQLConnection;
@@ -65,23 +66,18 @@ end;
 procedure ReadIniFile;
 
 var IniFile : TIniFile;
-
+    I : integer;
 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');
+  For I:=1 to 8 do
+    FPdevBirthDates[i] := EncodeDate(1990+i,i,i);
 end;
 
 procedure CreateFConnection;
@@ -99,6 +95,8 @@ begin
 
   with Fconnection do
     begin
+    if dbhost<>'' then
+      Hostname:=dbhost;
     DatabaseName := dbname;
     UserName := dbuser;
     Password := dbpassword;