PDA

View Full Version : creating new sql database



prolink007
18th April 2010, 16:02
Hello,

I am working on a project currently to get my self more familiarized with qt+sqL. I would like the user to be able to press 'new' and when they do, qt will create a new database using sqL. Then the user can start modifying that database. They can save it and close it. Later they can come back and load that database or they can create another new one.

I was wondering how i would go about this? I am not sure how to get qt to create the new database.

Thanks for help in advance.

EDIT::

Actually, another question... i may know how to do this myself. If i were to use sqlite and i tried to open a connection to a non existant database, would it automatically create the database and then i could query the database to set up the tables and stuff? If that is the case, then i know how i would do this.

Lykurg
18th April 2010, 18:11
If you using SQLite just set a file (it will be created if it does not exists). Then use simple SQL commands like CREATE DATABASE database_name // only for MySql to create a database in SQLite this is the file.
CREATE TABLE Persons
(
P_Id int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
) // creates a table...

prolink007
18th April 2010, 21:58
Thats what i thought. I was looking at the docs for sqlite+qt and noticed that.

Thanks for the assistance.