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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| #include <stdio.h> //|
#include <string.h> //|
#include <sqlca.h> //|Importation des headers des fonctions de librairies
#include <stdlib.h> //|
#include <sqlda.h> //|
#include <sqlcpr.h> //|
#define UNAME_LEN 20 //|declaration constante fixe
#define PWD_LEN 11 //|
typedef char asciiz[PWD_LEN];
EXEC SQL TYPE asciiz IS CHARZ(PWD_LEN) REFERENCE;
asciiz username;
asciiz password;
struct table // declaration de structure
{
asciiz nom_table; //composant de cette structure
};
struct table_chaine
{
asciiz nom_table_chaine; //composant de cette structure
int Numero_enr;
struct table *debut;
};
void lister_tables (int i)
{
struct table *emp_rec_ptr=NULL;
struct table_chaine *tete_liste=NULL;
struct table_chaine *p_courant;
struct table_chaine *p_origine=NULL;
/* Allocation de la memoire pour la struture emp_info . */
if ((emp_rec_ptr =
(struct table *) malloc(sizeof(struct table))) == 0)
{
fprintf(stderr, "Memory allocation error.\n");
exit(EXIT_FAILURE);
}
/* Connection à ORACLE. */
strcpy(username, "scott"); //|met la valeur scott dans la variable username
strcpy(password, "tiger"); //|
EXEC SQL CONNECT :username IDENTIFIED BY :password; //connection a la base oracle
printf("\nConnected to ORACLE as user: %s\n", username); //impression du retour de la connection a oracle
EXEC SQL DECLARE user_tables CURSOR FOR //declaration de curseur 'salespeople'
SELECT table_name
FROM user_tables; //requete select executee
EXEC SQL OPEN user_tables; //l'ouverture du curseur , execution de la requete
EXEC SQL WHENEVER NOT FOUND DO break;
for (;;)
{
EXEC SQL FETCH user_tables INTO :emp_rec_ptr;
// printf ("%d %s\n",i++,emp_rec_ptr -> nom_table);
p_courant = malloc (sizeof (struct table_chaine));
strcpy (p_courant -> nom_table_chaine, emp_rec_ptr->nom_table);
p_courant -> Numero_enr =i;
if (i == 0)
{
p_origine=p_courant;
}
printf ("%d %s %d\n",i++,p_courant-> nom_table_chaine ,p_courant);
// p_courant ->debut=p_precedent;
p_courant -> debut = tete_liste ;
tete_liste = p_courant ;
}
p_courant=p_origine;
// while (p_courant != NULL)
for (;;)
{
printf ("%d %s %d\n",p_courant -> Numero_enr,p_courant-> nom_table_chaine ,p_courant);
// printf (" %d %s \n",p_courant -> Numero_enr,p_courant -> nom_table_chaine);
/* Passer à lélement suivant */
p_courant = p_courant -> debut;
}
/* Close the cursor. */
EXEC SQL CLOSE user_tables;
EXEC SQL COMMIT WORK RELEASE;
exit(EXIT_SUCCESS);
}
void main()
{
lister_tables (0);
} |
Partager