Russian Qt Forum

Qt => Базы данных => Тема начата: swift от Ноябрь 25, 2009, 10:00



Название: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 25, 2009, 10:00
Скажите пожалуйста а есть в открытом доступе драйвер для Oracle
и если есть то где его взять
а если нет то мог бы кто ни будь поделиться им
спасибо  :)


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: crossly от Ноябрь 25, 2009, 10:58
в исходниках src/sql/drivers/oci/


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 25, 2009, 16:12
ээээ
скачал
qt-x11-opensource-src-4.5.3.tar.gz                            

зашел по указанному пути

дальше по инструкции из qt-assistant
cd $QTDIR/src/plugins/sqldrivers/oci
 qmake "INCLUDEPATH+=/usr/include/oracle/10.1.0.3/client" "LIBS+=-L/usr/lib/oracle/10.1.0.3/client/lib -Wl,-rpath,/usr/lib/oracle/10.1.0.3/client/lib -lclntsh -lnnz10" oci.pro
 make

в моем случае
cat $ORACLE_HOME
cat: /usr/lib/oracle/xe/app/oracle/product/10.2.0/server: Is a directory

cd /home/swift/Tmp/qt-x11-opensource-src-4.5.3/src/sql/drivers/oci
qmake -project (у меня нет oci.pro)
qmake "INCLUDEPATH+=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server" "LIBS+=-L/usr/lib/oracle/xe/app/oracle/product/10.2.0/server -Wl,-rpath,/usr/lib/oracle/10.1.0.3/client/lib -lclntsh -lnnz10" oci.pro (у меня стоит oracle XE)
make
и получаю
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/oracle/10.2.0/client -I. -I. -o qsql_oci.o qsql_oci.cpp                                                                                        
In file included from qsql_oci.cpp:42:                                                                                                                                              
qsql_oci.h:47:46: error: QtSql/private/qsqlcachedresult_p.h: No such file or directory                                                                                              
qsql_oci.cpp:50:23: error: qsqlerror.h: No such file or directory                                                                                                                  
qsql_oci.cpp:51:23: error: qsqlfield.h: No such file or directory                                                                                                                  
qsql_oci.cpp:52:23: error: qsqlindex.h: No such file or directory                                                                                                                  
qsql_oci.cpp:53:23: error: qsqlquery.h: No such file or directory                                                                                                                  
qsql_oci.cpp:59:17: error: oci.h: No such file or directory                                                                                                                        
In file included from qsql_oci.cpp:42:                                                                                                                                              
qsql_oci.h:68: error: expected class-name before ‘{’ token                                                                                                                          
qsql_oci.h:80: error: ‘ValueCache’ has not been declared                                                                                                                            
qsql_oci.cpp:80: error: ‘OCIStmt’ was not declared in this scope                                                                                                                    
qsql_oci.cpp:80: error: template argument 1 is invalid                                                                                                                              
qsql_oci.cpp:90: error: ‘ub1’ does not name a type                                                                                                                                  
qsql_oci.cpp:91: error: ‘ub2’ does not name a type                                                                                                                                  
qsql_oci.cpp:93: error: ‘sb2’ was not declared in this scope                                                                                                                        
qsql_oci.cpp:93: error: template argument 1 is invalid                                                                                                                              
qsql_oci.cpp:93: error: invalid type in declaration before ‘;’ token                                                                                                                
qsql_oci.cpp:94: error: ‘ub2’ was not declared in this scope                                                                                                                        
qsql_oci.cpp:94: error: template argument 1 is invalid                                                                                                                              
qsql_oci.cpp:94: error: invalid type in declaration before ‘;’ token                                                                                                                
qsql_oci.cpp:98: error: ‘OCIError’ was not declared in this scope                                                                                                                  
qsql_oci.cpp:98: error: ‘err’ was not declared in this scope                                                                                                                        
qsql_oci.cpp:98: error: expected primary-expression before ‘int’                                                                                                                    
qsql_oci.cpp:102: error: ‘OCIError’ has not been declared                                                                                                                          
qsql_oci.cpp:103: error: ‘QSqlError::ErrorType’ has not been declared                                                                                                              
qsql_oci.cpp:103: error: ‘OCIError’ has not been declared                                                                                                                          
qsql_oci.cpp:111: error: ISO C++ forbids declaration of ‘OCIRowid’ with no type                                                                                                    
qsql_oci.cpp:111: error: expected ‘;’ before ‘*’ token                                                                                                                              
qsql_oci.cpp: In constructor ‘QOCIRowId::QOCIRowId(OCIEnv*)’:                                                                                                                      
qsql_oci.cpp:118: error: class ‘QOCIRowId’ does not have any field named ‘id’                                                                                                      
qsql_oci.cpp:120: error: expected type-specifier before ‘dvoid’                                                                                                                    
qsql_oci.cpp:120: error: expected ‘>’ before ‘dvoid’                                                                                                                                
qsql_oci.cpp:120: error: expected ‘(’ before ‘dvoid’                                                                                                                                
qsql_oci.cpp:120: error: ‘dvoid’ was not declared in this scope                                                                                                                    
qsql_oci.cpp:120: error: expected primary-expression before ‘>’ token                                                                                                              
qsql_oci.cpp:120: error: ‘id’ was not declared in this scope                                                                                                                        
qsql_oci.cpp:121: error: ‘OCI_DTYPE_ROWID’ was not declared in this scope                                                                                                          
qsql_oci.cpp: In destructor ‘QOCIRowId::~QOCIRowId()’:                                                                                                                              
qsql_oci.cpp:126: error: ‘id’ was not declared in this scope                                                                                                                        
qsql_oci.cpp:127: error: ‘OCI_DTYPE_ROWID’ was not declared in this scope                                                                                                          
qsql_oci.cpp:127: error: ‘OCIDescriptorFree’ was not declared in this scope                                                                                                        
qsql_oci.cpp: At global scope:                                                                                                                                                      
qsql_oci.cpp:145: error: ISO C++ forbids declaration of ‘OCIError’ with no type                                                                                                    
qsql_oci.cpp:145: error: expected ‘;’ before ‘*’ token                                                                                                                              
qsql_oci.cpp:147: error: ISO C++ forbids declaration of ‘OCIStmt’ with no type                                                                                                      
qsql_oci.cpp:147: error: expected ‘;’ before ‘*’ token                                                                                                                              
qsql_oci.cpp:153: error: ‘OCIBind’ has not been declared                                                                                                                            
qsql_oci.cpp:155: error: ‘OCIStmt’ has not been declared                                                                                                                            
qsql_oci.cpp:155: error: ‘OCIBind’ has not been declared                                                                                                                            
qsql_oci.cpp:155: error: ‘OCIError’ has not been declared                                                                                                                          
qsql_oci.cpp:156: error: ‘dvoid’ has not been declared                                                                                                                              
qsql_oci.cpp:156: error: ‘ub2’ has not been declared                                                                                                                                
qsql_oci.cpp: In member function ‘bool QOCIResultPrivate::isOutValue(int) const’:                                                                                                  
qsql_oci.cpp:162: error: ‘class QOCIResult’ has no member named ‘bindValueType’                                                                                                    
qsql_oci.cpp: In member function ‘bool QOCIResultPrivate::isBinaryValue(int) const’:                                                                                                
qsql_oci.cpp:164: error: ‘class QOCIResult’ has no member named ‘bindValueType’                                                                                                    
qsql_oci.cpp: In member function ‘void QOCIResultPrivate::setStatementAttributes()’:                                                                                                
qsql_oci.cpp:174: error: ‘sql’ was not declared in this scope                                                                                                                      
qsql_oci.cpp:175: error: ‘OCI_HTYPE_STMT’ was not declared in this scope                                                                                                            
qsql_oci.cpp:178: error: ‘OCI_ATTR_PREFETCH_ROWS’ was not declared in this scope                                                                                                    
qsql_oci.cpp:179: error: ‘err’ was not declared in this scope                                                                                                                      
qsql_oci.cpp:179: error: ‘OCIAttrSet’ was not declared in this scope                                                                                                                
qsql_oci.cpp:185: error: ‘sql’ was not declared in this scope                                                                                                                      
qsql_oci.cpp:186: error: ‘OCI_HTYPE_STMT’ was not declared in this scope                                                                                                            
qsql_oci.cpp:189: error: ‘OCI_ATTR_PREFETCH_MEMORY’ was not declared in this scope                                                                                                  
qsql_oci.cpp:190: error: ‘err’ was not declared in this scope                                                                                                                      
qsql_oci.cpp:190: error: ‘OCIAttrSet’ was not declared in this scope                                                                                                                
qsql_oci.cpp: At global scope:                                                                                                                                                      
qsql_oci.cpp:197: error: variable or field ‘setCharset’ declared void                                                                                                              
qsql_oci.cpp:197: error: ‘OCIBind’ was not declared in this scope                                                                                                                  
qsql_oci.cpp:197: error: ‘hbnd’ was not declared in this scope
qsql_oci.cpp:215: error: ‘int QOCIResultPrivate::bindValue’ is not a static member of ‘struct QOCIResultPrivate’
qsql_oci.cpp:215: error: ‘OCIStmt’ was not declared in this scope
qsql_oci.cpp:215: error: ‘sql’ was not declared in this scope
qsql_oci.cpp:215: error: ‘OCIBind’ was not declared in this scope
qsql_oci.cpp:215: error: ‘hbnd’ was not declared in this scope
qsql_oci.cpp:215: error: ‘OCIError’ was not declared in this scope
qsql_oci.cpp:215: error: ‘err’ was not declared in this scope
qsql_oci.cpp:215: error: expected primary-expression before ‘int’
qsql_oci.cpp:216: error: expected primary-expression before ‘const’
qsql_oci.cpp:216: error: ‘dvoid’ was not declared in this scope
qsql_oci.cpp:216: error: ‘indPtr’ was not declared in this scope
qsql_oci.cpp:216: error: ‘ub2’ was not declared in this scope
qsql_oci.cpp:216: error: ‘tmpSize’ was not declared in this scope
qsql_oci.cpp:216: error: expected primary-expression before ‘&’ token
qsql_oci.cpp:216: error: ‘tmpStorage’ was not declared in this scope
qsql_oci.cpp:216: error: initializer expression list treated as compound expression
qsql_oci.cpp:217: error: expected ‘,’ or ‘;’ before ‘{’ token
qsql_oci.cpp:96: warning: ‘QByteArray qMakeOraDate(const QDateTime&)’ declared ‘static’ but never defined
qsql_oci.cpp:97: warning: ‘QDateTime qMakeDate(const char*)’ declared ‘static’ but never defined
qsql_oci.cpp:102: warning: ‘void qOraWarning(const char*, int*)’ declared ‘static’ but never defined
qsql_oci.cpp:103: warning: ‘QSqlError qMakeError(const QString&, int, int*)’ declared ‘static’ but never defined



Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 25, 2009, 16:38
изменил в make строчку
INCPATH       = -I/home/swift/Tmp/qt-x11-opensource-src-4.5.3/include -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/oracle/10.2.0/client -I. -I.


не помогло :(


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: prometey от Ноябрь 25, 2009, 17:38
Тут похоже вышла небольшая путаница :) на самом деле ответ
в исходниках src/sql/drivers/oci/

частично правилен. олько вот это дрйвер QT для оракла. который работает на основе ораклового драйвера с помощью интерфейса OCI. тебе необходим набор оракловых драйверов. их можно абсолютно бесплатно скачать с сайта оракла. для нужной тебе версии. вот линк: http://www.oracle.com/technology/software/products/database/index.html
сверху 11-ка, ниже 10-ка. выбери то что тебе надо и качай client
(например
Oracle Database 10g Client Release 2 (10.2.0.1.0) for Linux x86
10201_client_linux32.zip (478,343,213 bytes) (cksum - 579193942)
)

но это ты скачаешь кучу софта плюс кучу всякой лабуды. это наиболее легкий вариант. или же можно скачать т.н. instant client. находится это счастье по адресу http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
распаковываешь всё это дело. потом устанавливаешь пути к либам, заголовочным файлам, и компилишь кутешный дривер. а вообще, на сколько помню где-то в доке кути было описание сборки дривера


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 25, 2009, 17:58
брррр
но у меня стоит клиент Oracle
и как я понимаю туда драйвера уже входят.....

у меня пока проблема в том что я не могу собрать из исходников qt сей драйвер


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: UVV от Ноябрь 26, 2009, 10:49
Ставь одиннадцатую.


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 10:52
Ставь одиннадцатую.

если у меня не будет коннектится то обязательно попробую 11
пока у меня не компилится сам драйвер
можно конечно сей ошибки с include править самому
но как то мне кажется это не совсем правильно


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: crossly от Ноябрь 26, 2009, 12:06
в исходниках src/sql/drivers/oci/
это путь к самому драйверу.... для его сборки надо указать ключ при компиляции Qt (при этом он слинкуется с QtSql)... либо собрать плагин... он лежит там где и все src/plugins/sqldrivers


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 13:19
в исходниках src/sql/drivers/oci/
это путь к самому драйверу.... для его сборки надо указать ключ при компиляции Qt (при этом он слинкуется с QtSql)... либо собрать плагин... он лежит там где и все src/plugins/sqldrivers

так
я уже понял что немного налошил
файл oci.pro нашел
но обнаружил что у меня нет директории
/usr/include/oracle/.........



Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 13:49
2prometey

ты гений
спасибо!!!!!

так
собрал
файл libqsqloci.so
кинул в
/usr/lib/qt4/plugins/sqldrivers
а что делать дальше?

QSqlDatabase: QOCI driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL QODBC3 QODBC


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: crossly от Ноябрь 26, 2009, 14:31
что значит кинул??..... сделал make install??


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 14:32
что значит кинул??..... сделал make install??

да
swift@asus:~/Tmp/qt-x11-opensource-src-4.5.3/src/plugins/sqldrivers/oci$ sudo make install
[sudo] password for swift:
install -m 755 -p "libqsqloci.so" "/usr/lib/qt4/plugins/sqldrivers/libqsqloci.so"

а в ответ
swift@asus:~/Учеба/oracle.qt45$ ./oracle
QSqlDatabase: QOCI driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL QODBC3 QODBC


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: crossly от Ноябрь 26, 2009, 14:34
какая версия qt в системе??


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 14:38
какая версия qt в системе??

эээээ
qt 4.5.2


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: crossly от Ноябрь 26, 2009, 14:49
какая версия qt в системе??

эээээ
qt 4.5.2
а ты пытаешся втюхать ей драйвер от 4.5.3


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 14:52
а ты пытаешся втюхать ей драйвер от 4.5.3

это так критично????
сейчас с 4.5.2 соберу....


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 15:13
пересобрал
там на выходе вышел точно такой же файл


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 15:16
эээээ
а заработало черт побери  ;D

ldconfig надо было запустить

crossly спасибо  :)


Название: Re: Драйвер для Oracle для Qt (Linux Kubuntu 9.10)
Отправлено: swift от Ноябрь 26, 2009, 18:16
Публикую тут решение сей проблемы

Дано:
Kubuntu 9.10 (версия kubuntu в данном случае не принципиально)
с установленным комплектом разработчика по Qt и Oracle Express Edition из репозитариев.
Задача:
установить соединение из Qt программы с базой данных.

Решение
По какой то причине в репозитарии нету скомпилированного драйвера под Oracle, но исходники самого sql драйвера
доступны в исходниках Qt.

Для начала нам необходимо скачать Instant Client Oracle
http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html
Обратите внимание что если у вас стоит Oracle Express Edition
то вам необходимы файлы из ветки 10.2
Скачиваете архив
разархивруете его
и идете по следующему пути(адресу)
/home/swift/Tmp/instantclient_10_2/sdk

Вас интересует содержимое директории include
с правами root создаете директорию /usr/include/oracle/10.2
и копируете в нее содержимое сей папки



Далее идем на сайт http://qt.nokia.com/downloads/linux-x11-cpp
И качаем оттуда исходники Qt.
(В репозитарии Kubuntu доступна версия Qt 4.5.2, на сайте по умолчанию предлагается скачать 4.5.3, что впринципе не принципиально,
если Вы хотите скачать исходники именно Qt 4.5.2 просто в ссылке меняете одну циферку и тем же wget спокойно ее качаете)

В моем случае я скачал ее по адресу
/home/swift/Tmp

разархивруем архив
и идем по следующему пути(адресу)
/home/swift/Tmp/qt-x11-opensource-src-4.5.2/src/plugins/sqldrivers/oci

Там должно быть три файла
README
main.cpp
oci.pro

Там выполняем следующующую команду
qmake "INCLUDEPATH+=/usr/include/oracle/10.2/" "LIBS+=-L//usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib/ -Wl,-rpath,/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib/ -lclntsh -lnnz10" oci.pro

Обратите внимание на пути, они должны соотвествовать пути где у вас установлен Oracle XE
Выполняем команду и получаем файл Makefile
Заходим в него и находим строчку которая начинается с INCPATH
Наша задача указать что лежат заголовочные файлы входящие в исходники.
В моем случае это вылилось в добавление туда следующей строки
-I/home/swift/Tmp/qt-x11-opensource-src-4.5.2/include

Сохраняем файл
и запускаем
сначало make
затем make install (эту команду необходимо запускать с правами root)

Затем необходимо переписать hash динамических библиотек. Это делается с помощью команды ldconfig.


Ну и теперь тестируем саму программу

#include <QtGui>
#include <QtSql>

int main(int argc, char **argv)
{
    QApplication a(argc,argv);
    QMainWindow mainwin;
....
    QSqlDatabase db;
    db.addDatabase("QOCI");
    db.setDatabaseName("XE");
    db.setUserName("system");
    db.setPassword("secret_word");
..............
    mainwin.show();
    return a.exec();
}

программа компилится стандартно
qmake -project
qmake
make