Failed to query in firebird with fdb in python 3

1

I try to make a query in a database using Firebird, this is my code:

import fdb
import os

ruta = 'localhost:C:/Users/Beto/Documents/Proyectos python/Ruby/sama.fdb'

try:
    con = fdb.connect(
    dsn = ruta,
    user = 'sysdba',
    password = '*******',
    charset = 'utf-8'
    )
    print('Conectado !!')
except:
    print('Fallo la conexion', ruta)



cx = con.cursor()
sql = 'SELECT * FROM user'
cx.execute(sql)

filas = cx.fetchall()
print(filas)
con.commit()
con.close()

But I get the error message:

Traceback (most recent call last):
  File "C:\Users\Beto\Documents\Proyectos python\Ruby\fire.py", line 22, in <module>
    cx.execute(sql)
  File "C:\Users\Beto\AppData\Local\Programs\Python\Python35\lib\site-packages\fdb\fbcore.py", line 3573, in execute
    self._ps = PreparedStatement(operation, self, True)
  File "C:\Users\Beto\AppData\Local\Programs\Python\Python35\lib\site-packages\fdb\fbcore.py", line 2182, in __init__
    "Error while preparing SQL statement:")
fdb.fbcore.DatabaseError: ('Error while preparing SQL statement:\n- SQLCODE: -104\n- Dynamic SQL Error\n- SQL error code = -104\n- Token unknown - line 1, column 15\n- user', -104, 335544569)
    
asked by Sinergia 09.05.2016 в 05:36
source

2 answers

1

the definition of your dsn is incorrect, you do not have to carry the word localhost: , since you are defining a path in c: /.

ruta = 'localhost:C:/Users/Beto/Documents/Proyectos python/Ruby/sama.fdb'

regularly the extension of the database is .db

link

    
answered by 09.05.2016 в 06:49
0

I already use php.pdo to connect and I do it like this:

    try {
        $co = new PDO("firebird:dbname=mibdfb;role=mirol", 'SYSDBA', 'masterkey'); 
        $co->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch (PDOException $e) {
        $co = null;
        $inf = "ERROR: ConectaBD: " . $e->getMessage();
    }           
    return ($co);

    **-el nombre de la base de datos "mibdfb" es un alias que esta descrito en el fichero: aliases.conf, de esta manera:
      mibdfb = C:/Users/Beto/Documents/Proyectos python/Ruby/sama.fdb
    
answered by 04.11.2017 в 09:23