views:

71

answers:

1

I have a windows program which generates PGP forms which will be filled in later.

Those PHP forms will populate a database. It looks very much like MySql, but I can't be certain, so let's call it ODBC.

And, yes, it does have to be a windows program.

There will also be PHP forms which query the database - examine which tables and fields it contains and then generates forms which can be used to search the database (e.g, it finds a table with fields "employee_name", etc and generates a form which lets you search based on employee name.


Let's call that design time and run time.

At design time, some manager or IT guy or similar gets to define the nature of the database and at runtime 1) a worker fills in the form daily and 2) management can extract reports.

Here's my question: given that the database is defined at "design time" (and populated at run time), where and how is best to do so?

1 I could use an ODBC interface from the windows program, but I am having difficulty finding something good to work with Delphi. Things like ADO and firebird tend to expect you to already have a database and allow you to manipulate it, but I can find no code example of how to create a database and some tables, so ...
2 I could used DOS commands from Delphi in my windows program. I just tried and got a response to MySql --version, but am not sure if MySql etc are more interactive. That is, can I use a script file or a very long stacked command with semicolons and returns separating? e.g 'CREATE DATABASE db; CREATE TABLE t1;'
3) Since the best way to work with databases seems to be PHP, perhaps my windows program could spit out a PHP page which would, when run in a browser, create the database.


I have tried to make this as uncomplicated as I can, but please feel free to ask questions. It may be that there are several valid ways, but there is probably one 'better' solution in terms of ease of implementation or maintenance.


Better scratch option 3. What if the user later wants to come back and have the windows program change the input form? It needs to update the database too.

A: 

Creating a database is usually a database administrator task. Unless it is a local database, maybe an embedded one, the user would need to know where and how create the database on the remote server, and she can have no clue about it. Where to store the database files? Which disks are available? And there could be many more parameters to set (memoery buffers size, etc.), users to be created and so on. And also you need very elevate privileges to be able to create a database, not something you give to average users or applications. Thereby usually you ask the database administrator to create your database/schema, he will give you the credentials you need to connect, and then your application (or its setup) will create and initialize the needed objects (tables, etc.). Creating table (and other object) is usually as simple as running "CREATE TABLE...." statements. Just remember SQL takes one command only, if you need to run several commands you have to send them one after another yourself, although there are Delphi components which are able to split a script in commands and run one after another.

ldsandon
Sorry, although I agree that what you describe might be normal, it is not how it is going to be with this project.A "management individual" will use a windows program to generate forms used for daily reports (let's say sales reports) and non-technical users will fill them in a browser.That means that the windows program will define the database, set permissions and passwords, etc, etc. I don't have any choice in that.
Mawg
There is no need to "define the database" each time the programs generate forms and user fills them. You have to define *once* a set of tables that will store your forms metadata and data. Same as well for application users. Database are not usually designed to be very dynamic structures, but to handle dynamic data.
ldsandon
+1 and I will award you the answer, since no one else seems interested. However ... "There is no need to "define the database" each time the programs generate forms and user fills them". I obviously explained poorly ... "each time the programs generate forms" is "design time" and might only be once (if they get it right first time), but "and user fills them" is "run-time" and should be every day, at least."Database are not usually designed to be very dynamic structures". Agreed, I am just wondering what I do if a customer decides to rename a field or add/delete one...
Mawg
You have two ways: the simplest one is to create a 1:1 mapping from your objects to database objects (i.e a form is a table, and form fields are the table fields). This way you have to issue DDL commands (create/alter table, etc.) every time a user wishes to change the form structure. Or you could design a set of tables to store form metadata and data (i.e. "forms", "forms_fields", "form_fields_data", etc.) , and then just change records (DML commands...) within those tables without never changing the table structure. It requires more code, though, but is very flexible.
ldsandon