Annotation of rpl/src/gestion_fichiers.c, revision 1.40

1.1       bertrand    1: /*
                      2: ================================================================================
1.40    ! bertrand    3:   RPL/2 (R) version 4.1.7
1.38      bertrand    4:   Copyright (C) 1989-2012 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.16      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Routines de gestion des fichiers
                     29: ================================================================================
                     30:   Entrées : nom du fichier
                     31: --------------------------------------------------------------------------------
                     32:   Sorties : 0, le fichier n'existe pas, -1, il existe.
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: /*
                     39:  * Génère un nom de fichier
                     40:  */
                     41: 
                     42: unsigned char *
                     43: creation_nom_fichier(struct_processus *s_etat_processus,
                     44:        unsigned char *chemin)
                     45: {
                     46:    /*
                     47:     * Le nom du fichier est créé à l'aide du pid du processus et
                     48:     * d'un numéro d'ordre pour ce processus.
                     49:     */
                     50: 
                     51:    logical1                        erreur;
                     52: 
                     53:    logical1                        existence;
                     54:    logical1                        ouverture;
                     55: 
                     56:    pthread_mutex_t                 exclusion = PTHREAD_MUTEX_INITIALIZER;
                     57: 
                     58:    unsigned char                   *nom;
                     59:    unsigned char                   tampon[256 + 1];
                     60: 
                     61:    unsigned long                   ordre_initial;
                     62:    unsigned long                   unite;
                     63: 
                     64:    static unsigned long            ordre = 0;
                     65: 
                     66:    if (pthread_mutex_lock(&exclusion) != 0)
                     67:    {
                     68:        return(NULL);
                     69:    }
                     70: 
                     71:    ordre_initial = ordre;
                     72: 
                     73:    if (pthread_mutex_unlock(&exclusion) != 0)
                     74:    {
                     75:        return(NULL);
                     76:    }
                     77: 
                     78:    do
                     79:    {
1.18      bertrand   80:        sprintf(tampon, "RPL-%lu-%lu-%lu", (unsigned long) getpid(),
1.1       bertrand   81:                (unsigned long) pthread_self(), ordre);
                     82: 
                     83:        if (chemin == NULL)
                     84:        {
                     85:            if ((nom = malloc((strlen(tampon) + 1) *
                     86:                    sizeof(unsigned char))) == NULL)
                     87:            {
                     88:                return(NULL);
                     89:            }
                     90: 
                     91:            strcpy(nom, tampon);
                     92:        }
                     93:        else
                     94:        {
                     95:            if ((nom = malloc((strlen(chemin) + strlen(tampon) + 2) *
                     96:                    sizeof(unsigned char))) == NULL)
                     97:            {
                     98:                return(NULL);
                     99:            }
                    100: 
                    101:            sprintf(nom, "%s/%s", chemin, tampon);
                    102:        }
                    103: 
                    104:        if (pthread_mutex_lock(&exclusion) != 0)
                    105:        {
                    106:            return(NULL);
                    107:        }
                    108: 
                    109:        ordre++;
                    110: 
                    111:        if (pthread_mutex_unlock(&exclusion) != 0)
                    112:        {
                    113:            return(NULL);
                    114:        }
                    115: 
                    116:        if (ordre == ordre_initial)
                    117:        {
                    118:            // Il n'existe plus aucun nom de fichier disponible...
                    119: 
                    120:            free(nom);
                    121:            return(NULL);
                    122:        }
                    123: 
                    124:        erreur = caracteristiques_fichier(s_etat_processus,
                    125:                nom, &existence, &ouverture, &unite);
                    126: 
                    127:        if (erreur != 0)
                    128:        {
                    129:            free(nom);
                    130:            return(NULL);
                    131:        }
                    132: 
                    133:        if (existence == d_vrai)
                    134:        {
                    135:            free(nom);
                    136:        }
                    137:    } while(existence == d_vrai);
                    138: 
                    139:    return(nom);
                    140: }
                    141: 
                    142: /*
                    143:  * Efface un fichier
                    144:  */
                    145: 
                    146: logical1
                    147: destruction_fichier(unsigned char *nom_fichier)
                    148: {
                    149:    return((unlink(nom_fichier) == 0) ? d_absence_erreur : d_erreur);
                    150: }
                    151: 
                    152: /*
                    153:  * Renvoie le descripteur en fonction de la structure de contrôle du fichier
                    154:  */
                    155: 
1.6       bertrand  156: struct_descripteur_fichier *
1.1       bertrand  157: descripteur_fichier(struct_processus *s_etat_processus,
                    158:        struct_fichier *s_fichier)
                    159: {
                    160:    logical1                    concordance_descripteurs;
                    161: 
                    162:    struct_liste_chainee        *l_element_courant;
                    163: 
                    164:    l_element_courant = (*s_etat_processus).s_fichiers;
                    165:    concordance_descripteurs = d_faux;
                    166: 
                    167:    while(l_element_courant != NULL)
                    168:    {
                    169:        if ((*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                    170:                .identifiant == (*s_fichier).descripteur)
                    171:        {
                    172:            if (((*((struct_descripteur_fichier *) (*l_element_courant).donnee))
                    173:                    .pid == (*s_fichier).pid) && (pthread_equal(
                    174:                    (*((struct_descripteur_fichier *) (*l_element_courant)
                    175:                    .donnee)).tid, pthread_self()) != 0))
                    176:            {
1.6       bertrand  177:                return((struct_descripteur_fichier *)
                    178:                        (*l_element_courant).donnee);
1.1       bertrand  179:            }
                    180:            else
                    181:            {
                    182:                concordance_descripteurs = d_vrai;
                    183:            }
                    184:        }
                    185: 
                    186:        l_element_courant = (*l_element_courant).suivant;
                    187:    }
                    188: 
                    189:    if (concordance_descripteurs == d_vrai)
                    190:    {
                    191:        (*s_etat_processus).erreur_execution = d_ex_fichier_hors_contexte;
                    192:    }
                    193:    else
                    194:    {
                    195:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    196:    }
                    197: 
                    198:    return(NULL);
                    199: }
                    200: 
                    201: /*
                    202:  * Recherche un chemin pour les fichiers temporaires
                    203:  */
                    204: 
                    205: unsigned char *
                    206: recherche_chemin_fichiers_temporaires(struct_processus *s_etat_processus)
                    207: {
                    208:    file                *fichier;
                    209: 
                    210:    unsigned char       *candidat;
                    211:    unsigned char       *chemin;
                    212:    unsigned char       *chemins[] = { "$RPL_TMP_PATH",
                    213:                                "/tmp", "/var/tmp", NULL };
                    214:    unsigned char       *nom_candidat;
                    215: 
                    216:    unsigned long int   i;
                    217: 
                    218:    i = 0;
                    219:    chemin = NULL;
                    220: 
                    221:    while(chemin == NULL)
                    222:    {
                    223:        if (chemins[i][0] == '$')
                    224:        {
                    225:            candidat = getenv("RPL_TMP_PATH");
                    226: 
                    227:            if (candidat != NULL)
                    228:            {
                    229:                if ((nom_candidat = creation_nom_fichier(s_etat_processus,
                    230:                        candidat)) == NULL)
                    231:                {
1.23      bertrand  232:                    return(NULL);
1.1       bertrand  233:                }
                    234: 
                    235:                if ((fichier = fopen(nom_candidat, "w+")) != NULL)
                    236:                {
                    237:                    fclose(fichier);
                    238:                    unlink(nom_candidat);
                    239:                    free(nom_candidat);
                    240: 
                    241:                    if ((chemin = malloc((strlen(candidat) + 1)
                    242:                            * sizeof(unsigned char))) != NULL)
                    243:                    {
                    244:                        strcpy(chemin, candidat);
                    245:                    }
                    246:                    else
                    247:                    {
1.23      bertrand  248:                        return(NULL);
1.1       bertrand  249:                    }
                    250:                }
                    251:                else
                    252:                {
                    253:                    free(nom_candidat);
                    254:                }
                    255:            }
                    256:        }
                    257:        else
                    258:        {
                    259:            if ((nom_candidat = creation_nom_fichier(s_etat_processus,
                    260:                    chemins[i])) == NULL)
                    261:            {
1.23      bertrand  262:                return(NULL);
1.1       bertrand  263:            }
                    264: 
                    265:            if ((fichier = fopen(nom_candidat, "w+")) != NULL)
                    266:            {
                    267:                fclose(fichier);
                    268:                unlink(nom_candidat);
                    269:                free(nom_candidat);
                    270: 
                    271:                if ((chemin = malloc((strlen(chemins[i]) + 1)
                    272:                        * sizeof(unsigned char))) != NULL)
                    273:                {
                    274:                    strcpy(chemin, chemins[i]);
                    275:                }
                    276:                else
                    277:                {
1.23      bertrand  278:                    return(NULL);
1.1       bertrand  279:                }
                    280:            }
                    281:            else
                    282:            {
                    283:                free(nom_candidat);
                    284:            }
                    285:        }
                    286: 
                    287:        i++;
                    288:    }
                    289: 
                    290:    return chemin;
                    291: }
                    292: 
                    293: 
                    294: /*
1.6       bertrand  295:  * Fonction d'interrogation du fichier
                    296:  */
1.1       bertrand  297: 
                    298: logical1
                    299: caracteristiques_fichier(struct_processus *s_etat_processus,
                    300:        unsigned char *nom, logical1 *existence, logical1 *ouverture,
                    301:        unsigned long *unite)
                    302: {
                    303:    int                             descripteur;
                    304: 
                    305:    logical1                        erreur;
                    306: 
                    307:    struct_liste_chainee            *l_element_courant;
                    308: 
                    309:    (*unite) = 0;
                    310:    (*ouverture) = d_faux;
                    311:    (*existence) = d_faux;
                    312: 
1.4       bertrand  313:    if ((descripteur = open(nom, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) == -1)
1.1       bertrand  314:    {
                    315:        if (errno == EEXIST)
                    316:        {
                    317:            // Le fichier préexiste.
                    318: 
                    319:            erreur = d_absence_erreur;
                    320:            (*existence) = d_vrai;
                    321: 
                    322:            // On chercher à savoir si le fichier est ouvert. S'il est ouvert,
                    323:            // on renvoie son unité de rattachement.
                    324: 
                    325:            l_element_courant = (*s_etat_processus).s_fichiers;
                    326: 
                    327:            while(l_element_courant != NULL)
                    328:            {
                    329:                if (strcmp((*((struct_descripteur_fichier *)
                    330:                        (*l_element_courant).donnee)).nom, nom) == 0)
                    331:                {
                    332:                    if (((*((struct_descripteur_fichier *) (*l_element_courant)
                    333:                            .donnee)).pid == getpid()) &&
                    334:                            (pthread_equal((*((struct_descripteur_fichier *)
                    335:                            (*l_element_courant).donnee)).tid, pthread_self())
                    336:                            != 0))
                    337:                    {
                    338:                        (*ouverture) = d_vrai;
1.6       bertrand  339: 
1.1       bertrand  340:                        (*unite) = (unsigned long)
                    341:                                fileno((*((struct_descripteur_fichier *)
1.6       bertrand  342:                                (*l_element_courant).donnee))
                    343:                                .descripteur_c);
1.1       bertrand  344:                        break;
                    345:                    }
                    346:                }
                    347: 
                    348:                l_element_courant = (*l_element_courant).suivant;
                    349:            }
                    350:        }
1.37      bertrand  351:        else if (errno == EACCES)
                    352:        {
                    353:            // Le répertoire n'est pas accessible en écriture. On tente
                    354:            // l'ouverture du fichier.
                    355: 
                    356:            if ((descripteur = open(nom, O_RDONLY, S_IRUSR | S_IWUSR)) == -1)
                    357:            {
                    358:                // Le fichier n'existe pas.
                    359:                close(descripteur);
                    360:                erreur = d_absence_erreur;
                    361:            }
                    362:            else
                    363:            {
                    364:                erreur = d_absence_erreur;
                    365:                (*existence) = d_vrai;
                    366: 
                    367:                // On chercher à savoir si le fichier est ouvert.
                    368:                // S'il est ouvert, on renvoie son unité de rattachement.
                    369: 
                    370:                l_element_courant = (*s_etat_processus).s_fichiers;
                    371: 
                    372:                while(l_element_courant != NULL)
                    373:                {
                    374:                    if (strcmp((*((struct_descripteur_fichier *)
                    375:                            (*l_element_courant).donnee)).nom, nom) == 0)
                    376:                    {
                    377:                        if (((*((struct_descripteur_fichier *)
                    378:                                (*l_element_courant).donnee)).pid == getpid())
                    379:                                && (pthread_equal(
                    380:                                (*((struct_descripteur_fichier *)
                    381:                                (*l_element_courant).donnee)).tid,
                    382:                                pthread_self()) != 0))
                    383:                        {
                    384:                            (*ouverture) = d_vrai;
                    385: 
                    386:                            (*unite) = (unsigned long)
                    387:                                    fileno((*((struct_descripteur_fichier *)
                    388:                                    (*l_element_courant).donnee))
                    389:                                    .descripteur_c);
                    390:                            break;
                    391:                        }
                    392:                    }
                    393: 
                    394:                    l_element_courant = (*l_element_courant).suivant;
                    395:                }
                    396:            }
                    397:        }
1.1       bertrand  398:        else
                    399:        {
                    400:            erreur = d_erreur;
                    401:        }
                    402:    }
                    403:    else
                    404:    {
                    405:        close(descripteur);
                    406:        unlink(nom);
                    407:        erreur = d_absence_erreur;
                    408:    }
                    409: 
                    410:    return(erreur);
                    411: }
                    412: 
1.6       bertrand  413: 
                    414: /*
                    415: ================================================================================
                    416:   Routines d'initialisation des fichiers à accès direct et indexé
                    417: ================================================================================
                    418:   Entrées : pointeur sur le fichier SQLITE
                    419: --------------------------------------------------------------------------------
                    420:   Sorties : drapeau d'erreur
                    421: --------------------------------------------------------------------------------
                    422:   Effets de bord : néant
                    423: ================================================================================
                    424: */
                    425: 
                    426: /*
                    427:  * Un fichier à accès direct se compose d'une seule table :
                    428:  * 1: identifiant (entier sur 64 bits) -> enregistrement
                    429:  *
                    430:  * Un fichier à accès indexé comporte trois tables :
                    431:  * 1 : contrôle
                    432:  * 2 : clef (unique) -> identifiant (entier sur 64 bits)
                    433:  * 3 : identifiant -> collection d'enregistrements
                    434:  *
                    435:  * La table de contrôle contient
                    436:  * 1/ la position de la clef pour les fichiers à accès indexés
                    437:  */
                    438: 
                    439: static logical1
                    440: initialisation_controle(struct_processus *s_etat_processus, sqlite3 *sqlite,
1.8       bertrand  441:        integer8 position_clef, logical1 fichier_indexe)
1.6       bertrand  442: {
                    443:    const char              commande1[] =
1.8       bertrand  444:            "create table control(id integer primary key asc, key integer)";
1.6       bertrand  445:    const char              commande2[] =
1.8       bertrand  446:            "insert into control (id, key) values (1, %lld)";
1.6       bertrand  447:    const char              *queue;
                    448: 
                    449:    sqlite3_stmt            *ppStmt;
                    450: 
1.8       bertrand  451:    unsigned char           *commande;
                    452: 
1.6       bertrand  453:    if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt,
                    454:            &queue) != SQLITE_OK)
                    455:    {
                    456:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    457:        return(d_erreur);
                    458:    }
                    459: 
                    460:    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    461:    {
                    462:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    463:        return(d_erreur);
                    464:    }
                    465: 
                    466:    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    467:    {
                    468:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    469:        return(d_erreur);
                    470:    }
                    471: 
                    472:    if (fichier_indexe == d_vrai)
                    473:    {
1.8       bertrand  474:        if (alsprintf(&commande, commande2, position_clef) < 0)
                    475:        {
1.9       bertrand  476:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1.8       bertrand  477:            return(d_erreur);
                    478:        }
                    479: 
                    480:        if (sqlite3_prepare_v2(sqlite, commande, strlen(commande), &ppStmt,
1.6       bertrand  481:                &queue) != SQLITE_OK)
                    482:        {
1.8       bertrand  483:            free(commande);
1.6       bertrand  484:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    485:            return(d_erreur);
                    486:        }
                    487: 
                    488:        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    489:        {
1.8       bertrand  490:            free(commande);
1.6       bertrand  491:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    492:            return(d_erreur);
                    493:        }
                    494: 
                    495:        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    496:        {
1.8       bertrand  497:            free(commande);
1.6       bertrand  498:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    499:            return(d_erreur);
                    500:        }
1.8       bertrand  501: 
                    502:        free(commande);
1.6       bertrand  503:    }
                    504: 
                    505:    return(d_absence_erreur);
                    506: }
                    507: 
                    508: logical1
                    509: initialisation_fichier_acces_indexe(struct_processus *s_etat_processus,
1.8       bertrand  510:        sqlite3 *sqlite, integer8 position_clef, logical1 binaire)
1.6       bertrand  511: {
                    512:    const char              commande1[] =
                    513:            "create table data(id integer primary key asc, key_id integer, "
1.8       bertrand  514:            "data text, sequence integer)";
1.6       bertrand  515:    const char              commande10[] =
                    516:            "create table key(id integer primary key asc, key text)";
                    517:    const char              commande2[] =
                    518:            "create table data(id integer primary key asc, key_id integer, "
1.8       bertrand  519:            "data blob, sequence integer)";
1.6       bertrand  520:    const char              commande20[] =
                    521:            "create table key(id integer primary key asc, key blob)";
                    522:    const char              commande3[] =
                    523:            "create index data_idx on data(key_id)";
                    524:    const char              commande4[] =
                    525:            "create index key_idx on key(key)";
                    526:    const char              *queue;
                    527: 
                    528:    sqlite3_stmt            *ppStmt;
                    529: 
1.8       bertrand  530:    if (initialisation_controle(s_etat_processus, sqlite, position_clef, d_vrai)
1.6       bertrand  531:            != d_absence_erreur)
                    532:    {
                    533:        return(d_erreur);
                    534:    }
                    535: 
                    536:    if (binaire == d_faux)
                    537:    {
                    538:        if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt,
                    539:                &queue) != SQLITE_OK)
                    540:        {
                    541:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    542:            return(d_erreur);
                    543:        }
                    544: 
                    545:        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    546:        {
                    547:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    548:            return(d_erreur);
                    549:        }
                    550: 
                    551:        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    552:        {
                    553:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    554:            return(d_erreur);
                    555:        }
                    556: 
                    557:        if (sqlite3_prepare_v2(sqlite, commande10, strlen(commande10), &ppStmt,
                    558:                &queue) != SQLITE_OK)
                    559:        {
                    560:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    561:            return(d_erreur);
                    562:        }
                    563: 
                    564:        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    565:        {
                    566:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    567:            return(d_erreur);
                    568:        }
                    569: 
                    570:        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    571:        {
                    572:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    573:            return(d_erreur);
                    574:        }
                    575:    }
                    576:    else
                    577:    {
                    578:        if (sqlite3_prepare_v2(sqlite, commande2, strlen(commande2), &ppStmt,
                    579:                &queue) != SQLITE_OK)
                    580:        {
                    581:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    582:            return(d_erreur);
                    583:        }
                    584: 
                    585:        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    586:        {
                    587:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    588:            return(d_erreur);
                    589:        }
                    590: 
                    591:        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    592:        {
                    593:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    594:            return(d_erreur);
                    595:        }
                    596: 
                    597:        if (sqlite3_prepare_v2(sqlite, commande20, strlen(commande20), &ppStmt,
                    598:                &queue) != SQLITE_OK)
                    599:        {
                    600:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    601:            return(d_erreur);
                    602:        }
                    603: 
                    604:        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    605:        {
                    606:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    607:            return(d_erreur);
                    608:        }
                    609: 
                    610:        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    611:        {
                    612:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    613:            return(d_erreur);
                    614:        }
                    615:    }
                    616: 
                    617:    if (sqlite3_prepare_v2(sqlite, commande3, strlen(commande3), &ppStmt,
                    618:            &queue) != SQLITE_OK)
                    619:    {
                    620:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    621:        return(d_erreur);
                    622:    }
                    623: 
                    624:    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    625:    {
                    626:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    627:        return(d_erreur);
                    628:    }
                    629: 
                    630:    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    631:    {
                    632:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    633:        return(d_erreur);
                    634:    }
                    635: 
                    636:    if (sqlite3_prepare_v2(sqlite, commande4, strlen(commande4), &ppStmt,
                    637:            &queue) != SQLITE_OK)
                    638:    {
                    639:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    640:        return(d_erreur);
                    641:    }
                    642: 
                    643:    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    644:    {
                    645:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    646:        return(d_erreur);
                    647:    }
                    648: 
                    649:    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    650:    {
                    651:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    652:        return(d_erreur);
                    653:    }
                    654: 
                    655:    return(d_absence_erreur);
                    656: }
                    657: 
                    658: logical1
                    659: initialisation_fichier_acces_direct(struct_processus *s_etat_processus,
                    660:        sqlite3 *sqlite, logical1 binaire)
                    661: {
                    662:    const char              commande1[] =
1.7       bertrand  663:            "create table data(id integer primary key asc, data text)";
1.6       bertrand  664:    const char              commande2[] =
1.7       bertrand  665:            "create table data(id integer primary key asc, data blob)";
1.6       bertrand  666:    const char              commande3[] =
                    667:            "create index data_idx on data(id)";
                    668:    const char              *queue;
                    669: 
                    670:    sqlite3_stmt            *ppStmt;
                    671: 
1.8       bertrand  672:    if (initialisation_controle(s_etat_processus, sqlite, (integer8) 0, d_faux)
1.6       bertrand  673:            != d_absence_erreur)
                    674:    {
                    675:        return(d_erreur);
                    676:    }
                    677: 
                    678:    if (binaire == d_faux)
                    679:    {
                    680:        if (sqlite3_prepare_v2(sqlite, commande1, strlen(commande1), &ppStmt,
                    681:                &queue) != SQLITE_OK)
                    682:        {
                    683:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    684:            return(d_erreur);
                    685:        }
                    686: 
                    687:        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    688:        {
                    689:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    690:            return(d_erreur);
                    691:        }
                    692: 
                    693:        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    694:        {
                    695:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    696:            return(d_erreur);
                    697:        }
                    698:    }
                    699:    else
                    700:    {
                    701:        if (sqlite3_prepare_v2(sqlite, commande2, strlen(commande2), &ppStmt,
                    702:                &queue) != SQLITE_OK)
                    703:        {
                    704:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    705:            return(d_erreur);
                    706:        }
                    707: 
                    708:        if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    709:        {
                    710:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    711:            return(d_erreur);
                    712:        }
                    713: 
                    714:        if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    715:        {
                    716:            (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    717:            return(d_erreur);
                    718:        }
                    719:    }
                    720: 
                    721:    if (sqlite3_prepare_v2(sqlite, commande3, strlen(commande3), &ppStmt,
                    722:            &queue) != SQLITE_OK)
                    723:    {
                    724:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    725:        return(d_erreur);
                    726:    }
                    727: 
                    728:    if (sqlite3_step(ppStmt) != SQLITE_DONE)
                    729:    {
                    730:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    731:        return(d_erreur);
                    732:    }
                    733: 
                    734:    if (sqlite3_finalize(ppStmt) != SQLITE_OK)
                    735:    {
                    736:        (*s_etat_processus).erreur_systeme = d_es_erreur_fichier;
                    737:        return(d_erreur);
                    738:    }
                    739: 
                    740:    return(d_absence_erreur);
                    741: }
                    742: 
1.1       bertrand  743: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>