developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 12 years ago

Closed 11 years ago

Last modified 10 years ago

#590 closed enhancement (fixed)

Feature: make PDO/sqlite database path specification relative

Reported by: maurice Owned by: Julien
Priority: normal Milestone: Jelix 1.2 beta
Component: jelix:db Version: trunk
Severity: normal Keywords: sqlite
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version: 5.2.5

Description

php5.x+ allows using sqlite3 as PDO database with absotute path to the database file.

In order to make a web application with sqlite database relocatable, one should be able to build the path from the path of the web application itself.

But Jelix use ini file which only allows key-value driver spécification.

    ;dsn=sqlite:var/data/actu.org.sqlite3              ; NOT ALLOWED
    dsn=sqlite:/home/.../.../var/data/actu.org.sqlite3 ; NOT RELOCATABLE

So the require feature consists of add (or change) the specification of a sqlite database in dbprofiles.ini.php file to accept some relative path (suggestion has been proposed to adapt the jDbPDOConnection class)

Solution 1 : allow some variable interpretation

    dsn=sqlite:{$APP_DIR}/var/data/actu.org.sqlite3
    ; OR
    dsn=sqlite:{$JELIX_DIR}/var/data/actu.org.sqlite3

Solution 2: post-parse dsn path

    ; the dns is parsed, and modified to replace a possible relative path by an absolute one
    ; The path is relative to the APP_DIR.
    driver=pdo
    dsn=sqlite:var/data/actu.org.sqlite3 

Solution 3 (cut dsn in several parts)

    driver=pdo

    ;dsn=sqlite:/home/.../.../var/data/actu.org.sqlite3
    dsntype = sqlite

    ; just the file name itself
    dsnfile = actu.org.sqlite3

    ; a way to tell the base file if relative specif is used
    dsnbasedir = ABSOLUTE | APP_DIR | JELIX_DIR

    ; the dir can be absolute. il ut is relative the défault is relative to APP_DIR
    ; usless other dir is spécified by the previous key
    dsndir = var/data

Not sure which is better for minimize coding but the first solution allow simple one without some magic hidden process as for solution 2. Solution 3 has to be refine (many new keywords should be add which is not a good thing)

-- Maurice

Attachments (1)

590-jdb-pdo-sqlite-relative-path.diff (697 bytes) - added by Julien 11 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 12 years ago by maurice

  • Type changed from bug to enhancement

comment:2 Changed 12 years ago by laurentj

  • Component changed from jelix to jelix:db
  • Milestone set to Jelix 1.1 beta 1
  • Priority changed from high to normal
  • Severity changed from major to normal

The behavior will be the same as the jDb driver for sqlite : the path will be relative to var/db/sqlite/

comment:3 Changed 12 years ago by maurice

  • Cc Maurice.Diamantini@… removed

comment:4 Changed 12 years ago by maurice

Bon, suite à la remarque de Loïc, je reprends sur ce ticket la discussion du forum [Bidouille ... PDO sqlite ?|http://jelix.org/forums/read.php?4,3006,3008#msg-3008]

        #JELIX_APP_PATH#

| Franchement horrible, alors que partout ailleurs dans la conf on utilise simplement le raccourci "app:".

Oui, j'avais pas vu d'exemples dans ce fichier de conf. Du coup en refouillant dans tes sources ça donne quelque chose comme ça (la vérif d'existance du fichier est sous-traitée au parent ;-) :

Constructeur du fichier "jelix/db/jDbPDOConnection.class.php"

        unset($prof['driver']);
        if ($this->dbms == 'sqlite') {
            $profil['dsn'] = str_replace(array('lib:','app:'), 
                                         array(LIB_PATH, JELIX_APP_PATH), 
                                         $profil['dsn']);
        }
        parent::__construct($profil['dsn'], $user, $password, $prof);

Exempe d'utilisation :

        [testapp_sqlite_pdo]
        driver=pdo
        ; dsn=sqlite:app:var/db/sqlite/testapp.sqlite3
        dsn=sqlite:app:/../var/data/testapp.sqlite3

P.S.
C'est pas un patch hein ! Juste quelques lignes de code pas forcément correctes par rapport à Jelix et à ses conventions.

comment:5 Changed 12 years ago by bballizlife

Using app: and lib: would be ok for me.

But what about the comment of laurentj ?

The behavior will be the same as the jDb driver for sqlite : the path will be relative to var/db/sqlite/

Do we force sqlite databases files to always be in var/db/sqlite/ or can we put them elsewhere and use lib: and app: in the config path ?

The main thing here is to have a consistent feature between jDb and PDO.

comment:6 Changed 12 years ago by laurentj

  • Milestone Jelix 1.1 beta 1 deleted

comment:7 Changed 11 years ago by laurentj

  • Milestone set to Jelix 1.2

comment:8 Changed 11 years ago by Julien

  • Owner set to Julien
  • review set to review?
  • Status changed from new to assigned
  • Summary changed from Feature: make PDP/sqlite database path specification relative to Feature: make PDO/sqlite database path specification relative
  • Version changed from 1.0.3 to trunk

+1 for "app:" (and maybe "lib:", why not)

I think it could be restrictive to force "var/db/sqlite/" as relative path: multiple apps could share the same database (front and backoffice for example).

also, the dsn in dbprofiles should be compatible with "native" dsn, which supports absolute paths.

Changed 11 years ago by Julien

comment:9 Changed 11 years ago by laurentj

  • review changed from review? to review+

ok

comment:10 Changed 11 years ago by Julien

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:11 Changed 10 years ago by laurentj

  • Documentation needed set
Note: See TracTickets for help on using tickets.