Results 1 to 11 of 11

Thread: Windows OCI QSqlDatabase connection

  1. #1
    Join Date
    Feb 2012
    Location
    New Orleans
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Windows OCI QSqlDatabase connection

    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.

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtSql>
    3. #include <QDebug>
    4. #include <QSqlDatabase>
    5. #include "iostream"
    6. #include "qsql_oci.h"
    7. #include "qsql_oci.cpp"
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11.  
    12. QApplication a(argc, argv);
    13.  
    14. QSqlDatabase db = QSqlDatabase::addDatabase("OCI");
    15.  
    16. db.setHostName("datawarehouse");
    17. db.setDatabaseName("mydatabase");
    18. db.setUserName("hollyberry");
    19. db.setPassword("password");
    20.  
    21.  
    22. if(db.open())
    23. {
    24. qDebug() << "Opened!";
    25. db.close();
    26. }
    27. else
    28. {
    29. qDebug() << "Error = " << db.lastError().text();
    30. }
    31.  
    32.  
    33. return a.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 


    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....
    Attached Files Attached Files
    Last edited by Lykurg; 6th February 2012 at 19:25. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Windows OCI QSqlDatabase connection

    #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.

  3. #3
    Join Date
    Feb 2012
    Location
    New Orleans
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows OCI QSqlDatabase connection

    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!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Windows OCI QSqlDatabase connection

    What should that pq library be? How does your pro file look like? Have you added that library?

  5. #5
    Join Date
    Feb 2012
    Location
    New Orleans
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows OCI QSqlDatabase connection

    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 +=

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Windows OCI QSqlDatabase connection

    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.
    Qt Code:
    1. LIBS += -L"C:/<whatever>/PostgreSQL/9.1/lib" -lpq
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to Lykurg for this useful post:

    hollyberry (8th February 2012)

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Windows OCI QSqlDatabase connection

    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.

  9. #8
    Join Date
    Feb 2012
    Location
    New Orleans
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows OCI QSqlDatabase connection

    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?

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Windows OCI QSqlDatabase connection

    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.

  11. The following user says thank you to ChrisW67 for this useful post:

    hollyberry (13th February 2012)

  12. #10
    Join Date
    Feb 2012
    Location
    New Orleans
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Windows OCI QSqlDatabase connection

    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>mingw3 2-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.

  13. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Windows OCI QSqlDatabase connection

    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 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
    Last edited by ChrisW67; 13th February 2012 at 22:20.

Similar Threads

  1. How to set x509 on a QSqlDatabase Connection?
    By m3rlin in forum Qt Programming
    Replies: 24
    Last Post: 21st February 2012, 04:04
  2. QSqlDatabase Connection Close on Destruction
    By Sanuden in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2011, 15:32
  3. QSqlDatabase connection timeout?
    By joseprl89 in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2011, 01:43
  4. QSqlDatabase PSQL connection options
    By leknarf in forum Qt Programming
    Replies: 0
    Last Post: 17th March 2010, 16:06
  5. Replies: 3
    Last Post: 22nd June 2006, 16:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.