Connecting to PostgreSQL

Hi,

I have successfully built my first c++ sample plugin with the SDK and I'm now trying to connect to the CMS (PostgreSQL) from my plugin.

I am assuming that the DzAssetMgr class is responsible for that but the SDK is for Daz version 4.5 and contains no information about the CMS which was introduced with a later version.

The scripting documentation at http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/assetmgr_dz seems to document a later state (4.9?), as the class has additional methods there, but that doesn't help me from the C++ side, I guess since the dzcore.lib file will have no information about the new methods.

So I thought I'll try connecting to PostgreSQL directly via Qt and have a peek what's in the database. The SDK ships with QtSql4.lib and has the headers for Qt SQL support, and this code compiles and links OK:

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
    db.setConnectOptions();
    QString dsn = QString("Driver={PostgreSQL};Server=%1;Port=17237;Database=%2;").arg("localhost").arg("dzcms");
    db.setDatabaseName(dsn);
    if (db.open()) ...  

But the db.open() call fails at run-time and lastError() says "Driver not loaded". Google now tells me that Qt4 tries to load a Postgres driver DLL named QPSQL and fails, and that DLL doesn't seem to be either in the SDK or in the Daz3D application directory.

So I'm out of ideas. Is there any way to connect to the CMS from a C++ plugin? How does Daz Studio itself connect if QPSQL is not shipped with Daz Studio? I'm happy to build my own postgres libpq library but wanted to ask first if that is really necessary.

Thank you for any info!

Comments

  • Daz isn't going to provide direct access to the database, to allow for flexibility as needs chnage, but a plug-in can run and obtain results from a script (if it has its own methods or members exposed to scripting) so you could use that to have a script do the tasks you want.

  • Thank you Richard, scripting from the plugin is an interesting idea!

  • EsemwyEsemwy Posts: 578

    The google says on Windows it is necessary to have the PostgreSQL /bin and /lib directories in your path in order for the driver to load properly. 

    https://stackoverflow.com/questions/7669987/what-is-the-correct-way-of-qsqldatabase-qsqlquery

    http://doc.qt.io/qt-5/sql-driver.html#qpsql

    I’m certain Richard is right and DAZ doesn’t want you doing this. Calling a script is almost certainly the right way. I just thought you should know. 

  • I have refrained from trying to connect to the database now and will try to use the script interfaces if necessary. I got that to work (for another problem in another plugin I am working on right now), so that works in principle. Great!

    For the record though, Daz still uses Qt4, not 5. :-)

Sign In or Register to comment.