[Lazarus] Make table with TDataset structure

Michael Van Canneyt michael at freepascal.org
Thu Jun 25 19:40:21 CEST 2015



On Mon, 22 Jun 2015, aradeonas wrote:

> Vary good.
> Please let me know when it ready.

I committed the example, it's called 'createsql'. It's about 200 lines of code.
It should work with all supported database types.

Examples:

home: >./createsql -h
Usage: /home/michael/FPC/trunk/packages/fcl-db/examples/createsql [options]
Where options is one or more of:
-h  --help              this help message
-c  --connection-type=ctype   Set connection type (required)
-d  --database=db       database connection name (required)
-s  --sql=sql           SQL to execute (optional)
-t  --table=tablename   tablename to use for statement (required)
-y  --type=stype        Statement type (required) one of ddl, select, insert, update, delete)
-k  --keyfields=fields  Comma-separated list of key fields (required for delete, update, optional for select,ddl)
-u  --user=username     User name to connect to database
-p  --password=password Password of user to connect to database with
Where ctype is one of :
   firebird
   mysql 4.0
   mysql 4.1
   mysql 5.0
   odbc
   oracle
   postgresql
   sqlite3


home: >./createsql -c firebird -d localhost:/home/firebird/timetrack.fb -u NNN -p PPP -t PROJECT -y update -k PJ_ID
UPDATE PROJECT
SET
   PJ_ID = :PJ_ID,
   PJ_NAME = :PJ_NAME
WHERE
   (PJ_ID = :OLDPJ_ID)
home: >./createsql -c firebird -d localhost:/home/firebird/timetrack.fb -u NNN -p PPP -t PROJECT -y INSERT -k PJ_ID
INSERT INTO PROJECT
   (PJ_ID,
   PJ_NAME)
VALUES
   (:PJ_ID,
   :PJ_NAME)
home: >./createsql -c firebird -d localhost:/home/firebird/timetrack.fb -u NNN -p PPP -t PROJECT -y select -k PJ_ID
SELECT
   PJ_ID,
   PJ_NAME
FROM
   PROJECT
WHERE
   (PJ_ID = :PJ_ID)
home: >./createsql -c firebird -d localhost:/home/firebird/timetrack.fb -u NNN -p PPP -t PROJECT -y delete -k PJ_ID
DELETE FROM
   PROJECT
WHERE
   (PJ_ID = :OLDPJ_ID)
home: >./createsql -c firebird -d localhost:/home/firebird/timetrack.fb -u NNN -p PPP -t PROJECT -y ddl -k PJ_ID
CREATE TABLE PROJECT (
   PJ_ID VARCHAR(36) NOT NULL,
   PJ_NAME VARCHAR(30) NOT NULL,
   CONSTRAINT PROJECT_PK PRIMARY KEY (PJ_ID)
)

The SQL code generator has some more options to control how the SQL is generated, but I didn't implement those.

Hope this helps.

Michael.




More information about the Lazarus mailing list