View Full Version : Oracle Database Connection
ToddAtWSU
18th December 2007, 15:56
I am trying to connect to an Oracle database on Solaris 9. I am using Qt 4.3.0 Commerical Edition. I tried to connect using QOCI but it said I could not do this because I did not have the QOCI driver installed. So I reconfigured Qt and re-made it passing in the -qt-sql-oci flag to the configure script. Then when I tried to connect with the new install of Qt, it still printed out that the drivers are not installed. What would be the problem here? Also, should I be using QOCI or QODBC since I am on Solaris 9? Thanks!
Edit: I have found out we have Oracle 10g. So I was going to try and build the OCI plugin but I am having problems trying to do this. The docs say to "cd $QTDIR/plugins/src/sqldrivers/oci" but I don't have the directory. The only directory I have is $QTDIR/plugins/src/sqldrivers. Also, my include files and lib files are not located at "INCLUDEPATH+=/usr/include/oracle/10.1.0.3/client/" "LIBS+=-L/usr/lib/oracle/10.1.0.3/client/lib" like it says they should be. So how do I know what to put in for these lines? I am getting this information from here (http://doc.trolltech.com/4.3/sql-driver.html#qoci-for-the-oracle-call-interface-oci). So how can I install this? Thanks again!
mm78
19th December 2007, 10:08
That must be a typo in the docs. The correct directory should be $QTDIR/src/plugins/sqldrivers/oci.
The location of the Oracle include and library files depends on your system and your Oracle installation. The paths in the docs are just examples.
croftj
19th December 2007, 12:49
In the Commercial Qt distribution you should have the oci directory in the src tree.
In my case, I found it here:
/usr/local/Trolltech/qt-x11-commercial-src-4.2.3/src/sql/drivers/oci
It will put the plugin for the driver in the plugins directory of the destination:
/usr/local/Trolltech/Qt-4.2.3/plugins/sqldrivers/
I used the configuration parameter -prefix to set the destination:
-prefix /usr/local/Trolltech/Qt-4.2.3
Any programs built using qmake and moc from the resulting bin file will use that prefix to find the plugins directory.
Notice, I did my build under /usr/local/Trolltech and used that as the base of my destination also.
Now for the oracle, The environment variable $ORACLE_HOME should point to the base of your oracle installation. In my case:
/ORACLE_HOME=opt/oracle/product/10.1.0/db_1
This intern I used the configuration parameters
-I /opt/oracle/product/10.1.0/db_1/rdbms/public
and
-L /opt/oracle/product/10.1.0/db_1/lib
Just to make all of this clear, my configure line looked like this in the end:
configure -prefix /usr/local/Trolltech/Qt-4.2.3 -I /usr/include/pgsql \
-I /opt/oracle/product/10.1.0/db_1/rdbms/public \
-L /opt/oracle/product/10.1.0/db_1/lib -qt-gif -qt-libpng -qt \
-libmng -qt-libjpeg -plugin-sql-psql -plugin-sql-oci -qt-gif
At run time I had to add the directories to my LD_LIBRARY_PATH. It looks like:
LD_LIBRARY_PATH=:/opt/oracle/product/10.1.0/db_1/lib:/usr/local/Trolltech/Qt-4.2.0/lib
The versions in the paths may vary from yours but the overall structures remain reasonably constant.
Now if I can only make it work for Windows using MVC
ToddAtWSU
19th December 2007, 20:54
I can't wait to try this. I will set this up to run overnight and try it again. But one question I have is there a reason you chose to do -plugin-sql-oci instead of -qt-sql-oci? Thanks!
croftj
19th December 2007, 22:17
Not in particular. I've been tempted to try just compiling it in, but haven't had the need at this point to revisit it.
ToddAtWSU
20th December 2007, 15:08
I was able to manually build the driver on my own. I went to the $QTDIR/src/plugins/sqldrivers/oci directory. I then ran
$QTDIR/bin/qmake -o Makefile "INCLUDEPATH+=$ORACLE_HOME/rdbms/public" "LIBS+=-L$ORACLE_HOME/lib32" oci.pro
Then I ran make and it all worked well. The library was copied into $QTDIR/plugins/sqldrivers.
Inside my program's makefile I added these lines and also modified my LD_LIBRARY_PATH inside my .cshrc and re-sourced the .cshrc:
In the INC variable I added the line: -I$(QT)/include/QtSql
In the LIBS variable I added the line: -lQtSql
In the LIBHOMES variable I added the line: -L$(QT)/plugins/sqldrivers
I did a make clean followed by a make and everything compiled and linked correctly. But when I ran the program and tried to create a QSqlDatabase I got some printout errors. I first tried to create the database with the line
QSqlDatabase db = QSqlDatabase( "QOCI" );
The errors that print out are:
QSqlDatabase: QOCI driver not loaded
QSqlDatabse: available drivers:
According to this there are no database drivers installed anywhere. Is there something else I need to do to let the program or Qt know I made the QOCI driver? Thanks!
ToddAtWSU
20th December 2007, 15:18
Looking at other posts, it seems I have to make a QApplication to get the plugins. Is this correct? I will look into doing this. Thanks!
Edit: Well I added the QApplication creation call into my main. I made it the VERY first line in main so it would be created right away. Now whenever I try to open the database, it says I don't have OCI support. It says I do have the QSQLLite driver but that is it. I look in the /plugins/sqldrivers directory and it has 2 drivers there, the oci and sqllite drivers. How do I get Qt to recognize the oci driver. I have multiple copies of Qt, but I have set everything up to look at the one with the driver. What do I need to do to make Qt recognize the OCI driver? Thanks!!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.