PDA

View Full Version : Windows OCI QSqlDatabase connection



hollyberry
6th February 2012, 18:42
Hey ya'll! I'm new and in need of guidance. I cannot seem to find help throught the forum on the error I keep getting. I just want to connect to my database. I'm using windows xp professional operating system btw.

So here is my code in main.cpp for connecting to the database with a little popup that will tell me if the connection works. And I've attached the qsql_oci.h and qsql_oci.cpp files.


#include <QtGui/QApplication>
#include <QtSql>
#include <QDebug>
#include <QSqlDatabase>
#include "iostream"
#include "qsql_oci.h"
#include "qsql_oci.cpp"

int main(int argc, char *argv[])
{

QApplication a(argc, argv);

QSqlDatabase db = QSqlDatabase::addDatabase("OCI");

db.setHostName("datawarehouse");
db.setDatabaseName("mydatabase");
db.setUserName("hollyberry");
db.setPassword("password");


if(db.open())
{
qDebug() << "Opened!";
db.close();
}
else
{
qDebug() << "Error = " << db.lastError().text();
}


return a.exec();
}


The first error I continue to recieve is "OCIStmt was not declared in this scope".
Followed by "ub1 does not name a type" and many more errors like this! Grrrr....

Lykurg
6th February 2012, 19:24
#include "qsql_oci.cpp"You only include header files (*.h)!
Second, why are you including qsql_oci.h? And it has to be QOCI...

and we have [code] tags.

hollyberry
6th February 2012, 19:58
Wow! Okay, I took out #include "qsql_oci.cpp" and now my error is "cannot find -lpqdll.lib". I cannot seem to find that library to include it.

thank you so much for your help!

Lykurg
6th February 2012, 20:58
What should that pq library be? How does your pro file look like? Have you added that library?

hollyberry
6th February 2012, 21:28
My pro file is as follows:

QT += core gui sql

TARGET = slip

TEMPLATE = app

unix:LIBS += -lpq
win32:LIBS += libpqdll.lib


SOURCES += main.cpp \
qsql_oci.cpp

HEADERS += \
qsql_oci.h

FORMS +=

Lykurg
6th February 2012, 21:57
Ops, my bad, pq is part of Postgres... haven't worked with it so far. You probably have to add the path where the library could be found. Use the -L switch. E.g.
LIBS += -L"C:/<whatever>/PostgreSQL/9.1/lib" -lpq

ChrisW67
6th February 2012, 23:14
Your client application can simply address the QOCI plugin by name. You don't need any of the Qt SQL driver header files in your program at all. You do, however, have to build the Oracle OCI SQL driver plugin using the instructions provided in the documentation. To do that you will need the relevant Oracle-supplied client libraries installed, and know where they are.

hollyberry
8th February 2012, 20:28
Lykurg: I can't seem to find the library on my computer. Any idea where I could download it?

ChrisW67: I have attempted a few times to build the driver plugin. I keep getting error: mingw32-make: ***[debug-all] Error 2
Any ideas on how to fix this error?

ChrisW67
8th February 2012, 20:55
You don't need any part of PostgreSql, e.g. libpq, to build an Oracle plugin (i.e. QOCI). Which are you wanting to use? Which are you trying to build?

You could start by posting the compiler error messages that precede the message from make.

hollyberry
13th February 2012, 18:18
Hey guys! thanks again for all your help thus far. I'm sorry I'm a bit sporadic with this post. I only work a few days a week.

So ChrisW67, in building the QOCI plugin, I follow the following procedure:


set INCLUDE=%INCLUDE%;c:\oracle\oci\include
set LIB=%LIB%;c:\oracle\oci\lib\msvc
cd %QTDIR%\src\plugins\sqldrivers\oci
qmake oci.pro
nmake

and I get the following error:




D:\Qt\2010.05\qt\src\plugins\sqldrivers\oci>mingw32-make
mingw32-make -f Makefile.Debug all
mingw32-make[1]: Entering directory `D:/Qt/2010.05/qt/src/plugins/sqldrivers/oci
'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -
DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"..\..\..\..\include\QtCore" -I"..\..\..\..\i
nclude\QtSql" -I"..\..\..\..\include" -I"..\..\..\..\include\ActiveQt" -I"tmp\mo
c\debug_shared" -I"%INCLUDE%" -I" c:\oracle\product\11.1.0\client_1\oci\include"
-I"..\..\..\..\mkspecs\win32-g++" -o tmp\obj\debug_shared\qsql_oci.o ..\..\..\s
ql\drivers\oci\qsql_oci.cpp
..\..\..\sql\drivers\oci\qsql_oci.cpp:65:17: error: oci.h: No such file or direc
tory
..\..\..\sql\drivers\oci\qsql_oci.cpp:86: error: 'OCIStmt' was not declared in t
his scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:86: error: template argument 1 is invalid
..\..\..\sql\drivers\oci\qsql_oci.cpp:100: error: 'ub1' does not name a type
..\..\..\sql\drivers\oci\qsql_oci.cpp:105: error: 'ub2' does not name a type
..\..\..\sql\drivers\oci\qsql_oci.cpp:108: error: 'sb2' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:108: error: template argument 1 is invalid

..\..\..\sql\drivers\oci\qsql_oci.cpp:108: error: invalid type in declaration be
fore ';' token
..\..\..\sql\drivers\oci\qsql_oci.cpp:109: error: 'ub2' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:109: error: template argument 1 is invalid

..\..\..\sql\drivers\oci\qsql_oci.cpp:109: error: invalid type in declaration be
fore ';' token
..\..\..\sql\drivers\oci\qsql_oci.cpp:113: error: 'OCIError' was not declared in
this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:113: error: 'err' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:113: error: expected primary-expression be
fore 'int'
..\..\..\sql\drivers\oci\qsql_oci.cpp:117: error: 'OCIError' has not been declar
ed
..\..\..\sql\drivers\oci\qsql_oci.cpp:118: error: 'OCIError' has not been declar
ed
..\..\..\sql\drivers\oci\qsql_oci.cpp:126: error: ISO C++ forbids declaration of
'OCIRowid' with no type
..\..\..\sql\drivers\oci\qsql_oci.cpp:126: error: expected ';' before '*' token
..\..\..\sql\drivers\oci\qsql_oci.cpp: In constructor 'QOCIRowId::QOCIRowId(OCIE
nv*)':
..\..\..\sql\drivers\oci\qsql_oci.cpp:133: error: class 'QOCIRowId' does not hav
e any field named 'id'
..\..\..\sql\drivers\oci\qsql_oci.cpp:135: error: expected type-specifier before
'dvoid'
..\..\..\sql\drivers\oci\qsql_oci.cpp:135: error: expected '>' before 'dvoid'
..\..\..\sql\drivers\oci\qsql_oci.cpp:135: error: expected '(' before 'dvoid'
..\..\..\sql\drivers\oci\qsql_oci.cpp:135: error: 'dvoid' was not declared in th
is scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:135: error: expected primary-expression be
fore '>' token
..\..\..\sql\drivers\oci\qsql_oci.cpp:135: error: 'id' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:136: error: 'OCI_DTYPE_ROWID' was not decl
ared in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp: In destructor 'QOCIRowId::~QOCIRowId()':
..\..\..\sql\drivers\oci\qsql_oci.cpp:141: error: 'id' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:142: error: 'OCI_DTYPE_ROWID' was not decl
ared in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:142: error: 'OCIDescriptorFree' was not de
clared in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp: At global scope:
..\..\..\sql\drivers\oci\qsql_oci.cpp:160: error: ISO C++ forbids declaration of
'OCIError' with no type
..\..\..\sql\drivers\oci\qsql_oci.cpp:160: error: expected ';' before '*' token
..\..\..\sql\drivers\oci\qsql_oci.cpp:162: error: ISO C++ forbids declaration of
'OCIStmt' with no type
..\..\..\sql\drivers\oci\qsql_oci.cpp:162: error: expected ';' before '*' token
..\..\..\sql\drivers\oci\qsql_oci.cpp:167: error: 'OCIBind' has not been declare
d
..\..\..\sql\drivers\oci\qsql_oci.cpp:169: error: 'OCIStmt' has not been declare
d
..\..\..\sql\drivers\oci\qsql_oci.cpp:169: error: 'OCIBind' has not been declare
d
..\..\..\sql\drivers\oci\qsql_oci.cpp:169: error: 'OCIError' has not been declar
ed
..\..\..\sql\drivers\oci\qsql_oci.cpp:170: error: 'dvoid' has not been declared
..\..\..\sql\drivers\oci\qsql_oci.cpp:170: error: 'ub2' has not been declared
..\..\..\sql\drivers\oci\qsql_oci.cpp: In member function 'void QOCIResultPrivat
e::setStatementAttributes()':
..\..\..\sql\drivers\oci\qsql_oci.cpp:183: error: 'sql' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:189: error: 'OCI_HTYPE_STMT' was not decla
red in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:192: error: 'OCI_ATTR_PREFETCH_ROWS' was n
ot declared in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:193: error: 'err' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:193: error: 'OCIAttrSet' was not declared
in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:200: error: 'OCI_HTYPE_STMT' was not decla
red in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:203: error: 'OCI_ATTR_PREFETCH_MEMORY' was
not declared in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:204: error: 'err' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:204: error: 'OCIAttrSet' was not declared
in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp: At global scope:
..\..\..\sql\drivers\oci\qsql_oci.cpp:211: error: variable or field 'setCharset'
declared void
..\..\..\sql\drivers\oci\qsql_oci.cpp:211: error: 'OCIBind' was not declared in
this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:211: error: 'hbnd' was not declared in thi
s scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: 'int QOCIResultPrivate::bindVa
lue' is not a static member of 'struct QOCIResultPrivate'
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: 'OCIStmt' was not declared in
this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: 'sql' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: 'OCIBind' was not declared in
this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: 'hbnd' was not declared in thi
s scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: 'OCIError' was not declared in
this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: 'err' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:241: error: expected primary-expression be
fore 'int'
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: expected primary-expression be
fore 'const'
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: 'dvoid' was not declared in th
is scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: 'indPtr' was not declared in t
his scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: 'ub2' was not declared in this
scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: 'tmpSize' was not declared in
this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: expected primary-expression be
fore '&' token
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: 'tmpStorage' was not declared
in this scope
..\..\..\sql\drivers\oci\qsql_oci.cpp:242: error: initializer expression list tr
eated as compound expression
..\..\..\sql\drivers\oci\qsql_oci.cpp:243: error: expected ',' or ';' before '{'
token
..\..\..\sql\drivers\oci\qsql_oci.cpp:111: warning: 'QByteArray qMakeOraDate(con
st QDateTime&)' declared 'static' but never defined
..\..\..\sql\drivers\oci\qsql_oci.cpp:112: warning: 'QDateTime qMakeDate(const c
har*)' declared 'static' but never defined
..\..\..\sql\drivers\oci\qsql_oci.cpp:117: warning: 'void qOraWarning(const char
*, int*)' declared 'static' but never defined
..\..\..\sql\drivers\oci\qsql_oci.cpp:118: warning: 'QSqlError qMakeError(const
QString&, QSqlError::ErrorType, int*)' declared 'static' but never defined
mingw32-make[1]: *** [tmp/obj/debug_shared/qsql_oci.o] Error 1
mingw32-make[1]: Leaving directory `D:/Qt/2010.05/qt/src/plugins/sqldrivers/oci'


I realized my msvc folder is empty and that is where the missing library probably should go. In my attempts to connect using the Qt program I continually get the following error:


cannot find -lpqdll.lib

Any idea where I can download this library? I seem to have not luck on the internet.

ChrisW67
13th February 2012, 22:13
When you ran qmake in the QOCI plugin directory you gave several paths to the Oracle client files. Those paths are incorrect, which is why basic Oracle elements like "oci.h" cannot be found. You also claim to have run nmake when clearly you are using MingW: it should work anyway.

pqdll.lib is part of PostgreSql (http://www.postgresql.org/) and nothing to do with Oracle OCI database connections. Remove it from the LIBS line in your project PRO file.

edit: adjusted after re-reading your last post and the docs