kinterbas and Python

B

Balin

Hi all,
I have some problem with packege kinterbas for Firebird db connection
this is my code:

import kinterbasdb

class ConnessioneDB:
def initialize(self):
kinterbasdb.init(concurrency_level=1)
con = kinterbasdb.connect(host='192.168.1.20',
database='/home/db/TEST.FDB', user='SYSDBA', password='masterkey) <--- E

def testtable(self):
cur = con.cursor()
cur.execute("SELECT * FROM TEST")
for row in cur:
print str(row[0])

if __name__ == '__main__':
xCon = ConnessioneDB()
xCon.initialize() <-- ERROR
xCon.testtable()

use kinterbas.init(concurrency_level=?) to set the concurrency level
legally...why ? I'm try to set this value
kinterbas.init(concurrency_level=1) but don't work...please help..this
is my first program. Thanks in advanced.Marco.Italy
--
 
J

Jarek Zgoda

Balin napisa³(a):
con = kinterbasdb.connect(host='192.168.1.20',
database='/home/db/TEST.FDB', user='SYSDBA', password='masterkey) <--- E

I don't think it's valid. If you connect to remote host, don't give a
path to database, just its name. Specifying full path long time ago was
supported only using "local" connection.
 
P

Petr Jakes

Jarek, I am using it always like in the following example to connect to
the remote host and it works for me flawlessly.
Petr Jakes

import kinterbasdb as k
con = k.connect(
host='router.maren.cz',
database='/data/sysdat01.gdb',
user='SYSDBA', password='masterkey')
 
J

Jarek Zgoda

Petr Jakes napisa³(a):
Jarek, I am using it always like in the following example to connect to
the remote host and it works for me flawlessly.
Petr Jakes

import kinterbasdb as k
con = k.connect(
host='router.maren.cz',
database='/data/sysdat01.gdb',
user='SYSDBA', password='masterkey')

Sorry for confusion. Didn't expect that FB moved so far from Interbase.
 
D

David Rushby

Balin said:
Hi all,
I have some problem with packege kinterbas for Firebird db connection
this is my code:

import kinterbasdb

class ConnessioneDB:
def initialize(self):
kinterbasdb.init(concurrency_level=1)
con = kinterbasdb.connect(host='192.168.1.20',
database='/home/db/TEST.FDB', user='SYSDBA', password='masterkey) <--- E

If that's the actual code you're using, presumably you're getting an
error message like:
SyntaxError: EOL while scanning single-quoted string
because there's no closing quote after 'masterkey.

If that's not the actual code, could you post the actual code, the
actual error message, along with the versions of Python, Firebird,
KInterbasDB, and your operating system?
 
B

bssoft

Ok, thank..my python is 2.4.2
kinterbas is 3.2a1
Firebird is 1.5 on FEDORA CORE 4
my program code is run under winxp.... my actual code is equal above
and
when i past the code i forgot the quote but in my code the quote is
correctly.
My error code is :

concorrency level error
use kinterbas.init(concurrency_level=?) to set the concurrency level
legally...

thanks in advanced.
 
D

Dennis Lee Bieber

Hi all,
I have some problem with packege kinterbas for Firebird db connection
this is my code:
Looking at the sample code, you have more than "some problem"...
import kinterbasdb

class ConnessioneDB:
def initialize(self):
kinterbasdb.init(concurrency_level=1)

It would seem this would be more suited for an __init__() method...
Actually, the whole "initialize" should probably be an __init__
con = kinterbasdb.connect(host='192.168.1.20',
database='/home/db/TEST.FDB', user='SYSDBA', password='masterkey) <--- E

You've defined initialize as a method in a class. But you are
creating a local "con" that gets thrown away after the method returns.
def testtable(self):
cur = con.cursor()

When you invoke this method, there is no "con" object.


I suspect you need to put a "self." in front of all those object
names.
cur.execute("SELECT * FROM TEST")
for row in cur:

You have to "fetch" (.fetch(), .fetchall(), .fetchmany() ) the data
from the cursor...
print str(row[0])

if __name__ == '__main__':
xCon = ConnessioneDB()
xCon.initialize() <-- ERROR
xCon.testtable()

use kinterbas.init(concurrency_level=?) to set the concurrency level

If that is a literal quote, than there is something strange going
on...

Notice:
kinterbasdb.init(concurrency_level=1)
kinterbas.init(concurrency_level=?)
^^^^^^^^^**

DIFFERENT names!

I'm also not finding concurrency_level in the documentation I have
for kinterbasdb (3.1). Only usage of .init() is for...
Help on function init in module kinterbasdb:

init(type_conv=1)

I'd suggest something like:

-=-=-=-
import kinterbasdb

class ConnessioneDB:
def __init__(self):
#kinterbasdb.init(concurrency_level=1)
self.con = kinterbasdb.connect(host='192.168.1.20',
database='/home/db/TEST.FDB',
user='SYSDBA',
password='masterkey')
self.cur = self.con.cursor()
#assumes one cursor per connection

def testtable(self):
self.cur.execute("SELECT * FROM TEST")
for row in self.cur.fetchall():
print row[0]

def closeAll(self):
self.cur.close()
self.con.close()

if __name__ == '__main__':
xCon = ConnessioneDB() #creates connection & cursor
xCon.testtable() #uses cursor
xCon.closeAll()
--
 
D

Dennis Lee Bieber

You have to "fetch" (.fetch(), .fetchall(), .fetchmany() ) the data
from the cursor...
My apologies -- I just noticed the kinterbasdb document DOES use
your syntax... And it worked with my MySQL database too... Guess all my
code has always had to pass the data on to something else, so the use of
..fetchall() is my normal operation, such that I never realized cursors,
themselves, were iterable.
--
 
D

David Rushby

My error code is :

concorrency level error
use kinterbas.init(concurrency_level=?) to set the concurrency level
legally...

That's not the actual error message. The actual error message is:
"""
The concurrency level cannot be changed once it has been set. Use
kinterbasdb.init(concurrency_level=?) to set the concurrency level
legally.
"""

So, it seems that you're either trying to call kinterbasdb.init
multiple times, or you're performing an operation that calls
kinterbasdb.init implicitly, and later you're trying to call
kinterbasdb.init explicitly.

Either remove the kinterbasdb.init call entirely, or move it to a place
where it is called before you perform any database operations, and
won't be called again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top