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

Interfaces de programmation Oracle Discussion :

[OCI] Utilisation basique


Sujet :

Interfaces de programmation Oracle

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de Mayhem555
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 89
    Par défaut [OCI] Utilisation basique
    Salut à vous.

    Je programme actuellement un logiciel en C sous Linux (Fedora 8 :S) qui doit se connecter (puis rester connecté perpétuellement) à une base de données Oracle (version exacte inconnue mais récente).

    La seule chose que mon programme doit faire est un INSERT INTO blablabla... dans cette base. Ce qui vous en conviendrez est assez succint.

    Je cherchait donc une librairie ou une API qui me permettrait de me connecter et d'envoyer une telle requête à une base de donées Oracle. En fouillant sur leur site j'ai rapidement trouvé OCI.
    J'ai aussi trouvé sa documentation officielle qui est assez "hardcore" (1300 pages).
    Mon ami Google ne m'a pas donné trop de résultat vraiment probant sur d'éventuels tutoriels d'utilisation basique de cette API qui m'a l'air plutôt complexe.

    En connaissez vous ?

    J'ai réussi à trouver la doc de OCI mais pas les fichiers de la bibliothèque ou des .h.

    Merci de votre aide

  2. #2
    Rédacteur
    Avatar de Vincent Rogier
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    2 373
    Détails du profil
    Informations personnelles :
    Âge : 47
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 2 373
    Par défaut
    Il y a peu de doc OCI en francais....==> donc en anglais (HTML, PDF)

    Et effectivement, c'est une API très complexe ! Mais tellement puissante ...


    Si tu trouves OCI trop hard, tu peux essayer OCILIB qui est un wrapper autour d'OCI.

    Voici un tuto en français : Développer une application Oracle en C/C++ avec la librairie OCILIB

    Exemple de code pour se connecter, faire un loop de 1000 inserts avec OCILIB et se déconnecter :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    #include "ocilib.h"
     
    int main()
    {
        OCI_Connection *cn;
        OCI_Statement *st;
        int code;
        char value[20];
     
        if (OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT) == FALSE)
            return EXIT_FAILURE;
     
        cn = OCI_CreateConnection("db", "user", "pass", OCI_SESSION_DEFAULT);
     
        st = OCI_CreateStatement(cn);
     
        OCI_Prepare(st, "insert into my_table values(:code, :value)");
        OCI_BindInt(st, ":code", &code);
        OCI_BindString(st, ":value", value, 20);
     
        for (code = 1; code < 1000; code++);
        {
            sprintf(value, "value %i", code);    
            OCI_Execute(st);
        }
     
        OCI_Commit(cn);
        OCI_ConnectionFree(cn);    
        OCI_Cleanup();
     
        return EXIT_SUCCESS;
    }
    Vincent Rogier.

    Rubrique ORACLE : Accueil - Forum - Tutoriels - FAQ - Livres - Blog

    Vous voulez contribuer à la rubrique Oracle ? Contactez la rubrique !

    OCILIB (C Driver for Oracle)

    Librairie C Open Source multi-plateformes pour accéder et manipuler des bases de données Oracle

  3. #3
    Membre confirmé Avatar de Mayhem555
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 89
    Par défaut
    Salut Vincenzo et merci pour ta réponse.

    J'ai suivi ton conseil et essayé d'installer OCILIB.

    J'ai d'abord installé Oracle 10g Express Edition, téléchargé ici ( http://www.oracle.com/technology/sof...xelinsoft.html ),
    et j'ai suivi l'installation en suivant la doc, ICI.

    Donc Oracle s'installe bien. Par contre lors de l'install d'OCILIB, lorsque je lance le ./configure, je termine sur une erreur, voyez plutôt la trace.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for a thread-safe mkdir -p... /bin/mkdir -p
    checking for gawk... gawk
    checking whether make sets $(MAKE)... yes
    checking for gcc... gcc
    checking for C compiler default output file name... a.out
    checking whether the C compiler works... yes
    checking whether we are cross compiling... no
    checking for suffix of executables... 
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking for style of include used by make... GNU
    checking dependency style of gcc... gcc3
    checking for a BSD-compatible install... /usr/bin/install -c
    checking build system type... i686-pc-linux-gnu
    checking host system type... i686-pc-linux-gnu
    checking for a sed that does not truncate output... /bin/sed
    checking for grep that handles long lines and -e... /bin/grep
    checking for egrep... /bin/grep -E
    checking for ld used by gcc... /usr/bin/ld
    checking if the linker (/usr/bin/ld) is GNU ld... yes
    checking for /usr/bin/ld option to reload object files... -r
    checking for BSD-compatible nm... /usr/bin/nm -B
    checking whether ln -s works... yes
    checking how to recognize dependent libraries... pass_all
    checking how to run the C preprocessor... gcc -E
    checking for ANSI C header files... yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking dlfcn.h usability... yes
    checking dlfcn.h presence... yes
    checking for dlfcn.h... yes
    checking for g++... g++
    checking whether we are using the GNU C++ compiler... yes
    checking whether g++ accepts -g... yes
    checking dependency style of g++... gcc3
    checking how to run the C++ preprocessor... g++ -E
    checking for g77... no
    checking for xlf... no
    checking for f77... no
    checking for frt... no
    checking for pgf77... no
    checking for cf77... no
    checking for fort77... no
    checking for fl32... no
    checking for af77... no
    checking for xlf90... no
    checking for f90... no
    checking for pgf90... no
    checking for pghpf... no
    checking for epcf90... no
    checking for gfortran... gfortran
    checking whether we are using the GNU Fortran 77 compiler... yes
    checking whether gfortran accepts -g... yes
    checking the maximum length of command line arguments... 98304
    checking command to parse /usr/bin/nm -B output from gcc object... ok
    checking for objdir... .libs
    checking for ar... ar
    checking for ranlib... ranlib
    checking for strip... strip
    checking if gcc supports -fno-rtti -fno-exceptions... no
    checking for gcc option to produce PIC... -fPIC
    checking if gcc PIC flag -fPIC works... yes
    checking if gcc static flag -static works... yes
    checking if gcc supports -c -o file.o... yes
    checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
    checking whether -lc should be explicitly linked in... no
    checking dynamic linker characteristics... GNU/Linux ld.so
    checking how to hardcode library paths into programs... immediate
    checking whether stripping libraries is possible... yes
    checking if libtool supports shared libraries... yes
    checking whether to build shared libraries... yes
    checking whether to build static libraries... yes
    configure: creating libtool
    appending configuration tag "CXX" to libtool
    checking for ld used by g++... /usr/bin/ld
    checking if the linker (/usr/bin/ld) is GNU ld... yes
    checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
    checking for g++ option to produce PIC... -fPIC
    checking if g++ PIC flag -fPIC works... yes
    checking if g++ static flag -static works... yes
    checking if g++ supports -c -o file.o... yes
    checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
    checking dynamic linker characteristics... GNU/Linux ld.so
    checking how to hardcode library paths into programs... immediate
    appending configuration tag "F77" to libtool
    checking if libtool supports shared libraries... yes
    checking whether to build shared libraries... yes
    checking whether to build static libraries... yes
    checking for gfortran option to produce PIC... -fPIC
    checking if gfortran PIC flag -fPIC works... yes
    checking if gfortran static flag -static works... yes
    checking if gfortran supports -c -o file.o... yes
    checking whether the gfortran linker (/usr/bin/ld) supports shared libraries... yes
    checking dynamic linker characteristics... GNU/Linux ld.so
    checking how to hardcode library paths into programs... immediate
    checking for ranlib... (cached) ranlib
    checking for OCILIB path... is /usr/local
    checking for OCILIB package... current version is : 2.4.0 
    checking for OCILIB options... import: linkage, charset = ansi 
    checking for Oracle environnement... configure: error:  Oracle installation needed.
    C'est bizarre car Oracle est normalemet correctement installé. Où ai-je fais une connerie ?

    Merci de votre aide !!

  4. #4
    Membre confirmé Avatar de Mayhem555
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 89
    Par défaut
    Tiens, je me suis rendu compte que lorsque juste après l'install d'Oracle on me demande d'aller dans /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin
    et de lancer le script bash oracle_env.sh, celui ci ne m'a pas l'air de marcher car il est sensé donner une valeur à certaines variables d'environnement

    Ça c'est le contenu du script
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
    export ORACLE_HOME
    ORACLE_SID=XE
    export ORACLE_SID
    NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
    export NLS_LANG
    PATH=$ORACLE_HOME/bin:$PATH
    export PATH
    if [ $?LD_LIBRARY_PATH ]
    then
    	LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
    else
    	LD_LIBRARY_PATH=$ORACLE_HOME/lib
    fi
    export LD_LIBRARY_PATH
    Or derrière, un echo $ORACLE_HOME me renvoie une ligne vide.

    Est-ce la source de l'erreur ?

  5. #5
    Rédacteur
    Avatar de Vincent Rogier
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    2 373
    Détails du profil
    Informations personnelles :
    Âge : 47
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 2 373
    Par défaut
    Effectivement si ORACLE_HOME n'est pas défini, le configure d'OCILIB, avec les options par défaut, échouera.

    Donc, tu peux définir ORACLE_HOME dans ton .profile avec le répertoire d'oracle
    Vincent Rogier.

    Rubrique ORACLE : Accueil - Forum - Tutoriels - FAQ - Livres - Blog

    Vous voulez contribuer à la rubrique Oracle ? Contactez la rubrique !

    OCILIB (C Driver for Oracle)

    Librairie C Open Source multi-plateformes pour accéder et manipuler des bases de données Oracle

  6. #6
    Membre confirmé Avatar de Mayhem555
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 89
    Par défaut
    Salut Vincenzo !

    Je suis parvenu à installer OCILIB en utilisant la commande
    ./configure --with oracle-home=...
    puis le make, puis le make install.

    En revanche je n'arrive pas à compiler le petit exemple que tu m'as taper dans ce thread (au dessus). J'ai mis ça dans un main.c, mais la compilation pose des problèmes.

    Je n'ai pas tout à fait saisi la démarche à suivre dans ton tutoriel à la section III.E.

    J'ai fait un petit Makefile, mais je ne sais pas dans quelle mesure je doit ajouter les path des librairies sachant que je suis en UNICODE (Oracle 10g)

    Mon makefile est certainement foireux mais le compilateur / linker me dit qu'il ne trouve pas le fichier libnnz10.so ....qui après recherche n'existe nulle part

    Aurais tu un makefile typique pour compiler un main.c tout bête pour savoir si c'est moi qui foire (ce qui est fort probable).

    Merci

Discussions similaires

  1. [Débutant] Utilisation basique du TChart
    Par coxycross dans le forum C++Builder
    Réponses: 4
    Dernier message: 04/06/2012, 15h05
  2. Utilisation basique de dreamweaver
    Par Philp974 dans le forum Dreamweaver
    Réponses: 4
    Dernier message: 22/07/2009, 21h35
  3. [WebServices][WSDL] Utilisation (basique) de la Google API
    Par Rom_1 dans le forum Services Web
    Réponses: 5
    Dernier message: 07/07/2009, 22h55
  4. Utilisation basique de AJAX.
    Par tomagold dans le forum JSF
    Réponses: 3
    Dernier message: 13/12/2007, 11h52
  5. [OCI] utilisation de l'interface OCI
    Par Abdelkaoui dans le forum Interfaces de programmation
    Réponses: 1
    Dernier message: 04/09/2007, 19h21

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