Developpez.com - Rubrique PostgreSQL

Le Club des Développeurs et IT Pro

RoadMap : PostgreSql bientôt supporté par PureBasic ?

Le 2009-07-23 19:26:44, par comtois, Responsable Purebasic
Fred (l'auteur de PureBasic) souhaitait proposer un plugin pour supporter MySql simplement dans PureBasic, malheureusement, ça ne sera pas possible pour une question de licence :

Envoyé par Fred
I was looking to integrate native mysql support to PB via a database plugin, and while browsing the libmysql sources, i saw it was licensed as GPL. After a few search on google, even PHP5 removed native support of mysql because of license constraint.

What does it means ? It means than if you use this lib (dll or statically linked) in a non-GPL program you have a to buy a license to mysql. That's quite disappointing for such a 'free' database manager. Just wanted to let you know to avoid bad surprises.
Certains lui proposaient d'intégrer FireBird, et Fred semble vouloir s'orienter vers PostgreSql, à suivre...

Envoyé par Fred
I was looking for a "professional" database support. With ODBC you can already use mysql and such, but it's not build-in and can be problematic with crossplatform. The alternative to mysql is Postgresql which is an high peformance, totally free and reliable database server. So stay tuned .
  Discussion forum
6 commentaires
  • comtois
    Responsable Purebasic
    Fred n'a pas tardé, c'est déjà intégré dans la 4.40

    - Added UsePostgreSQLDatabase()
    Plus d'informations ici
  • comtois
    Responsable Purebasic
    Et voila mon premier essai avec PostgreSQL , je suis content ça marche

    Maintenant je n'ai plus qu'à lire les FAQ et tutoriels sur PostgreSQL.

    Code :
    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
    Procedure CheckDatabaseUpdate(Database, Query$)
       Result = DatabaseUpdate(Database, Query$)
       If Result = 0
          Debug DatabaseError()
       EndIf
       
       ProcedureReturn Result
    EndProcedure
    
    
    UsePostgreSQLDatabase()
    
    ; You should have a server running on localhost
    ;
    If OpenDatabase(0, "host=localhost port=5432", "postgres", "postgres")
    
      CheckDatabaseUpdate(0, "CREATE TABLE food (name CHAR(50), weight INT)")
      CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('apple', '10')")
      CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('pear', '5')")
      CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('banana', '20')")
      
      If DatabaseQuery(0, "SELECT * FROM food WHERE weight > 7")
      
         While NextDatabaseRow(0)
            Debug GetDatabaseString(0, 0)
         Wend
      
         FinishDatabaseQuery(0)
      EndIf
      
    Else
      Debug "Can't open database !"
    EndIf
  • comtois
    Responsable Purebasic
    Et là j'ai testé un des codes de la FAQ, je voulais surtout comparer la syntaxe avec PureBasic.

    Tester si un nombre est impair

    Code :
    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
    Procedure CheckDatabaseUpdate(Database, Query$)
       Result = DatabaseUpdate(Database, Query$)
       If Result = 0
          Debug DatabaseError()
       EndIf
       
       ProcedureReturn Result
    EndProcedure
     
     
    UsePostgreSQLDatabase()
     
    ; You should have a server running on localhost
    ;
    If OpenDatabase(0, "host=localhost port=5432", "postgres", "postgres")
     
      ;Valider les 2 lignes qui suivent si vous avez une erreur (pas de langage)
      ;t$ = "CREATE LANGUAGE plpgsql;"
      ;checkDatabaseUpdate(0, t$)
      
      t$ = "CREATE Or REPLACE FUNCTION public.estimpair (nombre integer) RETURNS boolean As "
      t$ + "$body$"
      t$ + "/* Cette fonction retourne true (vrai) si le nombre passé en argument est impair" 
      t$ + "   Exemple :  Select estimpair(12);"
      t$ + "              false"
      t$ + "*/"
      t$ + "BEGIN"
      t$ + " Return nombre % 2!=0;"
      t$ + "End;"
      t$ + "$body$"
      t$ + "LANGUAGE plpgsql;"
      checkDatabaseUpdate(0, t$)
     
     ; à partir d'ici on peut interroger la fonction 
     If DatabaseQuery(0, "Select estimpair(13);")
      
         While NextDatabaseRow(0)
            Debug GetDatabaseString(0, 0)
         Wend
      
         FinishDatabaseQuery(0)
      EndIf
    
      
    Else
      Debug "Can't open database !"
    EndIf
  • Progi1984
    Membre éprouvé
    Quelques améliorations possibles :

    Tu peux remplacer ta procédure par une macro.
    Tu as oublié un retour à la ligne aprés "; à partir d'ici on peut interroger la fonction".

    Avant de faire le CREATE Or REPLACE FUNCTION, tu devrais faire la vérification que "CREATE LANGUAGE plpgsql;" est fonctionnelle

    PS: tu n'es pas obligé de faire une fonction pgsql pour que ca marche
  • comtois
    Responsable Purebasic
    Je n'ai pas encore lu les tutoriels sur PostgreSQL, je voulais d'abord vérifier que ça fonctionnait bien avec la 4.40

    Je me suis contenté de saisir un code que je ne comprends pas, du moins pas dans le détail , ça me permet de savoir que ça existe, reste à étudier les subtilités.
  • comtois
    Responsable Purebasic
    Avec la doc c'est mieux, voici enfin la syntaxe pour ouvrir une base PostgreSQL:

    A PostgreSQL database has to be connected using OpenDatabase() before using any other database functions. PostgresSQL specific parameters can be passed in the 'DatabaseName$' parameter of OpenDatabase():
    - host: Name of host to connect to.
    - hostaddr: Numeric IP address of host to connect to.
    - port: Port number to connect to at the server host.
    - dbname: The database name. Defaults to be the same as the user name.
    - connect_timeout: Maximum wait for connection, in seconds (write as a decimal integer string).
    Zero or not specified means wait indefinitely.
    It is not recommended to use a timeout of less than 2 seconds.
    la version française de la doc n'est pas encore disponible.