IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Qt Discussion :

probleme avc otlv4.h


Sujet :

Qt

  1. #1
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20
    Par défaut probleme avc otlv4.h
    salut, j'ai besoin d'un example pour acceder a ma base de données oracle 9i avc Qt en utilisant otl.h .alors ecq qlq'1 peut de donner un example ou un code source je serais tres reconnaissant, merci

  2. #2
    Membre Expert

    Avatar de IrmatDen
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 727
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 727
    Par défaut
    Salut,

    T'as déjà regardé le module SQL et ses drivers? Y'a tout ce qu'il faut en tant qu'explication et qu'exemple.

  3. #3
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20
    Par défaut
    oui c deja fais mais le prb j'arrive pas a me connecté sur ma base de données oracle en utilisant unixodbc et le driver oracle.il me genre une erreur disant qu'il ne trouve pas les bibliotheques oracle pourtant je deja ajouter $ORACLE_HOME dans mes variables d'environnement. alors . mrd

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 83
    Par défaut
    Il faut avant tout construire le driver Oracle de Qt, comme indiqué dans la documentation :
    QOCI for the Oracle Call Interface (OCI)

  5. #5
    Futur Membre du Club
    Inscrit en
    Mai 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Âge : 50

    Informations forums :
    Inscription : Mai 2007
    Messages : 3
    Par défaut
    Bon pas de QT ici mais ça fonctionne

    Tu peux utiliser le dernier client OCI (le 10.2.4) pour accéder à une base oracle 9i.
    - installe le client OCI.
    - compile ton prog :par exemple
    g++ -Wall -DLINUX -D_GNU_SOURCE -D_REENTRANT -g -I/usr/local/include -c -o testOracle.o testOracle.cpp
    g++ -Wall -DLINUX -D_GNU_SOURCE -D_REENTRANT -lm -g -I/usr/local/include -L/usr/local/lib -locci -lclntsh -lociei -lnnz10 -o testOracle testOracle.o


    exemple : le fichier testoracle.cpp
    #include <iostream>
    using namespace std;
    #include <stdio.h>
    #define OTL_ORA10G_R2 // Compile OTL 4.0/OCI10gR2
    #include "otlv4.h" // include the OTL 4.0 header file

    //Global variables
    static const char oracleLogin[] = "user";
    static const char oraclePassword[] = "mdp";
    static const char oracleAddress[] = "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))";
    static const char oracleTable[] = "test_oci";
    otl_connect ObjectDatabase; // otl connect object
    bool bEraseTableFirst=false;

    /**
    * function insert
    * Insert rows into table
    */
    void insert()
    {
    char cRef[50], cColor[50], cQuery[250];
    int iIterator, iTag, iSize;

    //prepare insert query string
    strcpy(cQuery, "insert into ");
    strcat(cQuery, oracleTable);
    strcat(cQuery, "values(:cloth_tag<int>, :cloth_reference<char(101)>, :cloth_size<int>, :cloth_color<char(50)>)");

    otl_stream otlStreamOut(200, // buffer size
    cQuery, // SQL statement
    ObjectDatabase // connect object
    );
    otlStreamOut.set_commit(0); // turn off stream's "auto-commit"

    //just create some futuristic rows
    for(iIterator = 1 ; iIterator <= 25 ; ++iIterator)
    {
    iTag = 132456 + iIterator;
    if (iIterator < 10)
    {
    sprintf(cRef,"Ref000%d",iIterator);
    strcpy(cColor, "blue");
    }
    if (iIterator >= 10)
    {
    sprintf(cRef,"Ref00%d",iIterator);
    strcpy(cColor, "red");
    }
    iSize = (40 + iIterator) /2;

    otlStreamOut << iTag << cRef << iSize << cColor;
    }
    otlStreamOut << 523456 << "ref0026" << 42 << "blue";
    otlStreamOut << 378569 << "ref0027" << 72 << "green";
    otlStreamOut << 548622 << "ref0028" << 22 << "red";

    otlStreamOut.flush(); // flush the stream's dirty buffer:
    // execute the INSERT for the rows
    // that are still in the stream buffer

    ObjectDatabase.commit_nowait(); // commit with no wait (new feature of Oracle 10.2)
    }


    /**
    * function : select
    * Send queries to Oracle database and display result in the default output
    */
    void select()
    {
    int iTag, iSize;
    char cRef[100], cColor[100], cQuery[250];

    strcpy(cQuery, "select * from ");
    strcat(cQuery, oracleTable);
    strcat(cQuery, " where cloth_tag>=:f<int>");

    otl_stream otlStreamIn(200, // buffer size
    cQuery, // SELECT statement
    ObjectDatabase // connect object
    ); // create select stream

    otlStreamIn << 0; // assigning :f = 0 beginning
    // SELECT automatically executes when all input variables are
    // assigned. First portion of output rows is fetched to the buffer

    while(!otlStreamIn.eof())// while not end-of-data
    {
    otlStreamIn >> iTag >> cRef >> iSize >> cColor;
    cout << "Tag=" << iTag << ", Reference=" << cRef << ", Size=" << iSize << ", Color=" << cColor << endl;
    }
    }


    /**
    * function selectTag
    * send a query for just one row
    * @ int iTagQueried : the tag number
    * @ char* cRow : pointer to the char array for the result
    */
    void selectTag(int iSearchedTag, char* cRow)
    {
    int iTag, iSize;
    char cRef[100], cColor[100], cQuery[250], cTemp[50];

    //prepare request string
    strcpy(cQuery, "select * from ");
    strcat(cQuery, oracleTable);
    strcat(cQuery, " where cloth_tag=:f<int>");

    otl_stream otlStreamIn(200, // buffer size
    cQuery, // SELECT statement
    ObjectDatabase // connect object
    ); // create select stream

    otlStreamIn << iSearchedTag; // assigning :f
    //TODO verify if entry is existing before go on and not after
    otlStreamIn >> iTag >> cRef >> iSize >> cColor;

    if (iTag != iSearchedTag)
    {
    strcpy(cRow, "Tag not found");
    return;
    }

    strcpy(cRow, "Tag=");
    sprintf(cTemp,"%d",iTag);
    strcat(cRow, cTemp);
    strcat(cRow, ", Reference=");
    strcat(cRow, cRef);
    strcat(cRow, ", Size=");
    sprintf(cTemp,"%d",iSize);
    strcat(cRow, cTemp);
    strcat(cRow, ", Color=");
    strcat(cRow, cColor);
    }

    /**
    * main
    * Read all entries of the table (via select function)
    * Switch global flag bEraseTableFirst, the function drop the table and launch the
    * insert function before all.
    */
    int main()
    {
    char cConnect[250], cEraseTableQuery[250], cCreateTableQuery[250];
    char cRow[250];
    int iKeyboardEntry;

    //prepare drop query string
    strcpy(cEraseTableQuery, "drop table ");
    strcat(cEraseTableQuery, oracleTable);

    //prepare create query string
    strcpy(cCreateTableQuery, "create table ");
    strcat(cCreateTableQuery, oracleTable);
    strcat(cCreateTableQuery, "(cloth_tag number, cloth_reference varchar2(100),");
    strcat(cCreateTableQuery, " cloth_size number, cloth_color varchar2(50))");

    //prepare login/password@db string
    strcpy(cConnect, oracleLogin);
    strcat(cConnect, "/");
    strcat(cConnect, oraclePassword);
    strcat(cConnect, "@");
    strcat(cConnect, oracleAddress);

    otl_connect::otl_initialize(); // initialize OCI environment
    try
    {
    ObjectDatabase.rlogon(cConnect); // connect to Oracle

    if (bEraseTableFirst) //if table must be drop and recreate
    {
    otl_cursor::direct_exec( ObjectDatabase,
    cEraseTableQuery,
    otl_exception::disabled // disable OTL exceptions
    //not necessary for just droping a table :-)
    ); // drop table

    otl_cursor::direct_exec( ObjectDatabase,
    cCreateTableQuery); // create table

    insert(); // call to insert function
    }

    select(); // call to select function
    }
    catch(otl_exception& pException) // intercept OTL exceptions
    {
    cerr << pException.msg << endl; // print out error message
    cerr << pException.stm_text << endl; // print out SQL that caused the error
    cerr << pException.var_info << endl; // print out the variable that caused the error
    }

    while (iKeyboardEntry != 0)
    {
    cout << "Enter Tag number (0 to quit): " << endl;
    cin >> iKeyboardEntry;
    if (iKeyboardEntry != 0)
    {
    selectTag(iKeyboardEntry, cRow);
    cout << cRow << endl;
    }
    }

    ObjectDatabase.logoff(); // disconnect from Oracle
    return 0;
    }

Discussions similaires

  1. probleme avce JFreeChart
    Par dunod dans le forum Graphisme
    Réponses: 3
    Dernier message: 30/05/2012, 12h03
  2. Probleme avce href
    Par mouatasim dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 20/06/2011, 16h02
  3. probleme avc le temps réél
    Par kamouminator dans le forum SDL
    Réponses: 2
    Dernier message: 01/10/2006, 19h51
  4. Probleme avc internet explorer
    Par steeves5 dans le forum IE
    Réponses: 9
    Dernier message: 09/02/2006, 21h44
  5. [Kylix] Probleme d'execution de programmes...
    Par yopziggy dans le forum EDI
    Réponses: 19
    Dernier message: 03/05/2002, 14h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo