[Qt-interest] CREATE DATABASE with PostgreSQL don't work
Diego Schulz
dschulz at gmail.com
Sun Jan 15 13:25:24 CET 2012
On Sat, Dec 24, 2011 at 2:19 PM, Guenther Boelter <gboelter at gmail.com>wrote:
> Hello there!
>
> The following code works well with MySQL but not with PostgreSQL.
>
> QSqlQuery query( dbErpel );
> query.prepare( "CREATE DATABASE erpel" );
>
> if ( ! query.exec() )
> {
> sqlError( __FILE__, __LINE__, query.lastError().text() );
> return false;
> }
>
> With PostgreSQL lastQuery() returns "CREATE DATABASE erpel" but
> lastError() returns:
>
> QSqlError(-1, "QPSQL: Es konnte keine Abfrage erzeugt werden", "ERROR:
> syntax error at end of input
> LINE 1: EXECUTE
> ^
> ")
>
> What's wrong with that?
>
> Regards
>
> Guenther
Hi Guenther,
You don't really need to use prepare() for that. Just exec() the create
sentence like this:
bool ok = query.exec( "CREATE DATABASE erpel;" );
if(!ok){
qDebug() << query.lastError().databaseText();
// do something
}
diego
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20120115/8ca2290c/attachment.html
More information about the Qt-interest-old
mailing list