bug-jargal | Bonjour à tous,
Je commence en même temps le c et le precompilateur suscité d'oracle...
J'ai tatonné pas mal mais là j'aurais besoin d'un coup de main de la part d'une bonne âme .
Je n'arrive pas à trouver d'explication aux erreurs qui me restent...
Voici le code de mon petit machin:
Code :
- #include <stdio.h>
- #include <string.h>
- #include <sqlca.h>
- #include <stdlib.h>
- #include <sqlda.h>
- #include <sqlcpr.h>
- /* Declare variables. No declare section is
- needed if MODE=ORACLE. */
- EXEC SQL BEGIN DECLARE SECTION;
- char db_username[40];
- char db_passwd[40];
- char uid[81];
- char CreateRole[255];
- char GrantCreateSession[255];
- char GrantCreateTable[255];
- char GrantCreateView[255];
- char GrantCreateTrigger[255];
- char GrantUpdate[255];
- char GrantInsert[255];
- char GrantSelect[255];
- char GrantAlter[255];
- sql_cursor table_cursor;
- char owner_name[40];
- char role_name[80];
- char table_fqn[255];
- char used_table[50];
- int rec_nr = 0;
- EXEC SQL END DECLARE SECTION;
- void sql_error(msg)
- char *msg;
- {
- char err_msg[512];
- size_t buf_len, msg_len;
- EXEC SQL WHENEVER SQLERROR CONTINUE;
- printf("\n%s\n", msg);
- /* Call sqlglm() to get the complete text of the
- * error message.
- */
- buf_len = sizeof (err_msg);
- sqlglm(err_msg, &buf_len, &msg_len);
- printf("%.*s\n", msg_len, err_msg);
- EXEC SQL ROLLBACK RELEASE;
- exit(EXIT_FAILURE);
- }
- void main()
- {
- /*Get db username*/
- db_username = 0;
- printf("\nEnter db username (0 to quit): " );
- gets(db_username);
- if (db_username == 0)
- break;
- /*Get db passwd*/
- db_passwd = 0;
- printf("\nEnter db password (0 to quit): " );
- gets(db_passwd);
- if (db_passwd == 0)
- break;
-
- /*Get owner name*/
- printf("\nEnter schema owner name (0 to quit): " );
- gets(owner_name);
- if (owner_name == 0)
- break;
- /*Get role name*/
- role_name = 0;
- printf("\nEnter role name (0 to quit): " );
- gets(role_name);
- if (role_name == 0)
- break;
-
- /* Connect to ORACLE. */
- spintf(uid,"%s/%s",db_username,db_passwd);
- EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--" );
- EXEC SQL CONNECT :uid;
- printf("\nConnected to ORACLE as user: %s\n", db_username);
- rec_nr = EXEC SQL SELECT COUNT(*)
- FROM SYS.ALL_TABLES
- WHERE owner = :owner_name;
- /*retrieve table list in a cursor predefined structure*/
- EXEC SQL ALLOCATE :table_cursor;
- EXEC SQL EXECUTE
- BEGIN
- OPEN :table_cursor FOR SELECT TABLE_NAME FROM SYS.ALL_TABLES
- WHERE owner = :owner_name;
- END;
- END-EXEC;
- /*Create role*/
- //DDL statements can't be specified with host variables in it.
- sprintf(CreateRole, "EXEC SQL CREATE ROLE %s", role_name);
- EXEC SQL PREPARE q FROM :CreateRole;
- EXEC SQL EXECUTE q;
- /*Grant privileges to role*/
- sprintf(GrantCreateSession, "EXEC SQL GRANT CREATE SESSION TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantCreateSession;
- EXEC SQL EXECUTE q;
- sprintf(GrantCreateTable, "EXEC SQL GRANT CREATE TABLE TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantCreateTable;
- EXEC SQL EXECUTE q;
- sprintf(GrantCreateView, "EXEC SQL GRANT CREATE VIEW TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantCreateView;
- EXEC SQL EXECUTE q;
- sprintf(GrantCreateTrigger, "EXEC SQL GRANT CREATE TRIGGER TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantCreateTrigger;
- EXEC SQL EXECUTE q;
- for(int i = 0;i < rec_nr;i++)
- {
- used_table = table_cursor[i];
- sprintf(table_fqn, "%s.%s", owner_name, used_table);
- sprintf(GrantUpdate, "EXEC SQL GRANT UPDATE ON %s",table_fqn ," TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantUpdate;
- EXEC SQL EXECUTE q;
- sprintf(GrantInsert, "EXEC SQL GRANT INSERT ON %s",table_fqn ," TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantInsert;
- EXEC SQL EXECUTE q;
- sprintf(GrantSelect, "EXEC SQL GRANT SELECT ON %s",table_fqn ," TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantSelect;
- EXEC SQL EXECUTE q;
- sprintf(GrantAlter, "EXEC SQL GRANT Alter ON %s",table_fqn ," TO %s", role_name);
- EXEC SQL PREPARE q FROM :GrantAlter;
- EXEC SQL EXECUTE q;
- }
- EXEC SQL CLOSE :table_cursor;
- /*Role granting*/
- sprintf(GrantRoleToUser, "EXEC SQL GRANT %s",role_name ," TO %s", owner_name);
- EXEC SQL PREPARE q FROM :GrantRoleToUser;
- EXEC SQL EXECUTE q;
- sprintf(SetDefaultRole, "EXEC SQL ALTER USER %s",owner_name," DEFAULT ROLE %s", role_name);
- EXEC SQL PREPARE q FROM :SetDefaultRole;
- EXEC SQL EXECUTE q;
- printf("\nArrivederci.\n\n" );
- EXEC SQL COMMIT WORK RELEASE;
- exit(EXIT_SUCCESS);
- }
|
et les erreurs générées par la version win32 du precompilateur :
Citation :
Erreur à la ligne 117, colonne 12 dans le fichier grant_role.pc
rec_nr = EXEC SQL SELECT COUNT(*) ...........1
PLS-S-00201, l'identificateur 'SYS.ALL_TABLES' doit être déclaré
Erreur à la ligne 117, colonne 12 dans le fichier grant_role.pc
rec_nr = EXEC SQL SELECT COUNT(*) ...........1
PLS-S-00000, SQL Statement ignored
erreur sémantique en ligne 117, colonne 12, fichier grant_role.pc:
rec_nr = EXEC SQL SELECT COUNT(*) ...........1
PCC-S-02346, PL/SQL a trouvé des erreurs sémantiques
OPEN :table_cursor FOR SELECT TABLE_NAME FROM SYS.ALL_TABLES
..........................................................1
PLS-S-00201, l'identificateur 'SYS.ALL_TABLES' doit être déclaré
OPEN :table_cursor FOR SELECT TABLE_NAME FROM SYS.ALL_TABLES
...............................1
PLS-S-00000, SQL Statement ignored
erreur sémantique en ligne 125, colonne 5, fichier grant_role.pc:
BEGIN
....1
PCC-S-02346, PL/SQL a trouvé des erreurs sémantiques
erreur sémantique en ligne 188, colonne 30, fichier grant_role.pc:
EXEC SQL PREPARE q FROM :GrantRoleToUser;
.............................1
PCC-S-02322, identificateur inconnu rencontré
erreur sémantique en ligne 188, colonne 24, fichier grant_role.pc:
EXEC SQL PREPARE q FROM :GrantRoleToUser;
.......................1
PCC-S-02319, type de l'expression différent de son utilisation
erreur sémantique en ligne 192, colonne 30, fichier grant_role.pc:
EXEC SQL PREPARE q FROM :SetDefaultRole;
.............................1
PCC-S-02322, identificateur inconnu rencontré
erreur sémantique en ligne 192, colonne 24, fichier grant_role.pc:
EXEC SQL PREPARE q FROM :SetDefaultRole;
.......................1
PCC-S-02319, type de l'expression différent de son utilisation
|
globalement deux erreurs quoi...
par ailleurs, la version linux du même precompilateur me retourne carrément :
Citation :
Error at line 202, column 2 in file /home/oracle/grant_role.pc
}
.1
PCC-S-02010, found end-of-file while scanning string literal
Error at line 0, column 0 in file grant_role.pc
PCC-F-02102, Fatal error while doing C preprocessing
|
Je vois pas ou, et en plus, comment ce fait-il que la version windows ne m'insulte pas de la même maniére ?
A vot bon coeur messieurs, dames...
|