version 1.6, 2010/03/06 18:29:06
|
version 1.15, 2010/07/14 14:19:34
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.12 |
RPL/2 (R) version 4.0.18 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
Line 391 caracteristiques_fichier(struct_processu
|
Line 391 caracteristiques_fichier(struct_processu
|
|
|
static logical1 |
static logical1 |
initialisation_controle(struct_processus *s_etat_processus, sqlite3 *sqlite, |
initialisation_controle(struct_processus *s_etat_processus, sqlite3 *sqlite, |
logical1 fichier_indexe) |
integer8 position_clef, logical1 fichier_indexe) |
{ |
{ |
const char commande1[] = |
const char commande1[] = |
"create table control(id integer primary key asc, lock text)"; |
"create table control(id integer primary key asc, key integer)"; |
const char commande2[] = |
const char commande2[] = |
"insert into control (id, lock) values (2, '0')"; |
"insert into control (id, key) values (1, %lld)"; |
const char *queue; |
const char *queue; |
|
|
sqlite3_stmt *ppStmt; |
sqlite3_stmt *ppStmt; |
|
|
|
unsigned char *commande; |
|
|
if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, |
if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, |
&queue) != SQLITE_OK) |
&queue) != SQLITE_OK) |
{ |
{ |
Line 422 initialisation_controle(struct_processus
|
Line 424 initialisation_controle(struct_processus
|
|
|
if (fichier_indexe == d_vrai) |
if (fichier_indexe == d_vrai) |
{ |
{ |
if (sqlite3_prepare_v2(sqlite, commande2, strlen(commande2), &ppStmt, |
if (alsprintf(&commande, commande2, position_clef) < 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(d_erreur); |
|
} |
|
|
|
if (sqlite3_prepare_v2(sqlite, commande, strlen(commande), &ppStmt, |
&queue) != SQLITE_OK) |
&queue) != SQLITE_OK) |
{ |
{ |
|
free(commande); |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
return(d_erreur); |
return(d_erreur); |
} |
} |
|
|
if (sqlite3_step(ppStmt) != SQLITE_DONE) |
if (sqlite3_step(ppStmt) != SQLITE_DONE) |
{ |
{ |
|
free(commande); |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
return(d_erreur); |
return(d_erreur); |
} |
} |
|
|
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
{ |
{ |
|
free(commande); |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
return(d_erreur); |
return(d_erreur); |
} |
} |
|
|
|
free(commande); |
} |
} |
|
|
return(d_absence_erreur); |
return(d_absence_erreur); |
Line 447 initialisation_controle(struct_processus
|
Line 460 initialisation_controle(struct_processus
|
|
|
logical1 |
logical1 |
initialisation_fichier_acces_indexe(struct_processus *s_etat_processus, |
initialisation_fichier_acces_indexe(struct_processus *s_etat_processus, |
sqlite3 *sqlite, logical1 binaire) |
sqlite3 *sqlite, integer8 position_clef, logical1 binaire) |
{ |
{ |
const char commande1[] = |
const char commande1[] = |
"create table data(id integer primary key asc, key_id integer, " |
"create table data(id integer primary key asc, key_id integer, " |
"lock text)"; |
"data text, sequence integer)"; |
const char commande10[] = |
const char commande10[] = |
"create table key(id integer primary key asc, key text)"; |
"create table key(id integer primary key asc, key text)"; |
const char commande2[] = |
const char commande2[] = |
"create table data(id integer primary key asc, key_id integer, " |
"create table data(id integer primary key asc, key_id integer, " |
"lock blob)"; |
"data blob, sequence integer)"; |
const char commande20[] = |
const char commande20[] = |
"create table key(id integer primary key asc, key blob)"; |
"create table key(id integer primary key asc, key blob)"; |
const char commande3[] = |
const char commande3[] = |
Line 467 initialisation_fichier_acces_indexe(stru
|
Line 480 initialisation_fichier_acces_indexe(stru
|
|
|
sqlite3_stmt *ppStmt; |
sqlite3_stmt *ppStmt; |
|
|
if (initialisation_controle(s_etat_processus, sqlite, d_vrai) |
if (initialisation_controle(s_etat_processus, sqlite, position_clef, d_vrai) |
!= d_absence_erreur) |
!= d_absence_erreur) |
{ |
{ |
return(d_erreur); |
return(d_erreur); |
Line 600 initialisation_fichier_acces_direct(stru
|
Line 613 initialisation_fichier_acces_direct(stru
|
sqlite3 *sqlite, logical1 binaire) |
sqlite3 *sqlite, logical1 binaire) |
{ |
{ |
const char commande1[] = |
const char commande1[] = |
"create table data(id integer primary key asc, lock text)"; |
"create table data(id integer primary key asc, data text)"; |
const char commande2[] = |
const char commande2[] = |
"create table data(id integer primary key asc, lock blob)"; |
"create table data(id integer primary key asc, data blob)"; |
const char commande3[] = |
const char commande3[] = |
"create index data_idx on data(id)"; |
"create index data_idx on data(id)"; |
const char *queue; |
const char *queue; |
|
|
sqlite3_stmt *ppStmt; |
sqlite3_stmt *ppStmt; |
|
|
if (initialisation_controle(s_etat_processus, sqlite, d_faux) |
if (initialisation_controle(s_etat_processus, sqlite, (integer8) 0, d_faux) |
!= d_absence_erreur) |
!= d_absence_erreur) |
{ |
{ |
return(d_erreur); |
return(d_erreur); |
Line 680 initialisation_fichier_acces_direct(stru
|
Line 693 initialisation_fichier_acces_direct(stru
|
return(d_absence_erreur); |
return(d_absence_erreur); |
} |
} |
|
|
unsigned char * |
|
verrouillage_fichier_sqlite(struct_processus *s_etat_processus, |
|
sqlite3 *sqlite, unsigned char *operation) |
|
{ |
|
const char commande1[] = |
|
"select lock from control where id = 1"; |
|
const char commande2[] = |
|
"update control set lock = '%s'"; |
|
const char *queue; |
|
|
|
const unsigned char *resultat; |
|
|
|
sqlite3_stmt *ppStmt; |
|
|
|
unsigned char *verrou; |
|
|
|
resultat = NULL; |
|
|
|
if (operation == NULL) |
|
{ |
|
// Lecture du verrou |
|
|
|
if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt, |
|
&queue) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_step(ppStmt) != SQLITE_ROW) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_column_type(ppStmt, 0) != SQLITE_TEXT) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
resultat = sqlite3_column_text(ppStmt, 0); |
|
|
|
if ((verrou = malloc((strlen(resultat) + 1) * sizeof(unsigned char))) |
|
== NULL) |
|
{ |
|
return(NULL); |
|
} |
|
|
|
strcpy(verrou, resultat); |
|
|
|
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
} |
|
else |
|
{ |
|
// Positionnement d'un verrou |
|
|
|
if (alsprintf(&verrou, commande2, operation) < 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_prepare_v2(sqlite, verrou, strlen(verrou), &ppStmt, |
|
&queue) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_step(ppStmt) != SQLITE_DONE) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
if (sqlite3_finalize(ppStmt) != SQLITE_OK) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return(NULL); |
|
} |
|
|
|
free(verrou); |
|
verrou = NULL; |
|
} |
|
|
|
return(verrou); |
|
} |
|
|
|
// vim: ts=4 |
// vim: ts=4 |