Qt-interest Archive, July 2007
SqlDatabase
Message 1 in thread
I am not sure what to do.
I write the app that stores the data in the sql database.
When first run the app asks what type of database to use (sqlite, psql, mysql
or else), username, password and database name.
Then it should create database with sql "create database mydb".
But if i do something like
QSqlDatabase db = QSqlDatabase::addDatabase(type);
db.setDatabaseName("mydb");
db.open();
I get error that db is not exists.
How i can do such things?
--
[ signature omitted ]
Message 2 in thread
you need to create the database yourself
--------------------
Itamar Reis Peixoto
e-mail: itamar@xxxxxxxxxxxxxxxx
msn: itamarjp@xxxxxxxxxxxxx
skype: itamarjp
icq: 81053601
+55 34 3238 3845
+55 11 4063 5033
>I am not sure what to do.
> I write the app that stores the data in the sql database.
> When first run the app asks what type of database to use (sqlite, psql,
> mysql
> or else), username, password and database name.
>
> Then it should create database with sql "create database mydb".
> But if i do something like
>
> QSqlDatabase db = QSqlDatabase::addDatabase(type);
> db.setDatabaseName("mydb");
> db.open();
>
> I get error that db is not exists.
>
> How i can do such things?
>
>
--
[ signature omitted ]
Message 3 in thread
ivan demakov wrote:
> Then it should create database with sql "create database mydb".
> But if i do something like
>
> QSqlDatabase db = QSqlDatabase::addDatabase(type);
> db.setDatabaseName("mydb");
> db.open();
>
> I get error that db is not exists.
>
> How i can do such things?
Database creation, like many aspects of database management, varies from
RDBMS to RDBMS.
In PostgreSQL, for example, you would usually connect to the template
database (eg `template1') and issue the appropriate CREATE DATABASE
command (with OWNER specification etc) from there.
Other databases use other methods, and I'm not at all sure they all use
SQL to do it either. You might have to write database-specific code to
do the DB creation, either executing external binaries or using varying
SQL syntax and connection parameters for each database type.
--
[ signature omitted ]