helo,
I don't understand why my sqlite database is locked on a drop ( the code 
is following)
thanks for your explanation.


007-09-14 18:26:36,375 INFO 
sqlalchemy.engine.threadlocal.TLEngine.0x..f0 ROLLBACK
Traceback (most recent call last):
  File 
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", 
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Documents and Settings\pouchou.RECT\Mes documents\exemple 
formation python\sqlalchemy\simple-alchemy.py", line 107, in <module>
    engine.drop(os_table)
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1044, in drop
    self._run_visitor(self.dialect.schemadropper, entity, 
connection=connection, **kwargs)
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1069, in 
_run_visitor
    visitorcallable(self.dialect, conn, **kwargs).traverse(element)
  File "build\bdist.win32\egg\sqlalchemy\sql\visitors.py", line 63, in 
traverse
    meth(target)
  File "build\bdist.win32\egg\sqlalchemy\sql\compiler.py", line 922, in 
visit_table
    self.execute()
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1624, in 
execute
    return self.connection.execute(self.buffer.getvalue())
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 789, in 
execute
    return Connection.executors[c](self, object, multiparams, params)
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 799, in 
_execute_text
    self.__execute_raw(context)
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 850, in 
__execute_raw
    self._cursor_execute(context.cursor, context.statement, parameters, 
context=context)
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 867, in 
_cursor_execute
    raise exceptions.DBAPIError.instance(statement, parameters, e)
*OperationalError: (OperationalError) database table is locked '\nDROP 
TABLE os' ()*


# -*- coding: CP1252 -*-

from pprint import pprint
from sqlalchemy import create_engine, Table, Column, MetaData, Integer, 
Date, Unicode, Float, ForeignKey
from sqlalchemy.sql import select, and_

# Connexion à la base
engine = create_engine('sqlite://',echo=True)

# echo=True On voit les ordres sql générés pas SQLalchemy

# une metadata représente un ensemble de tables                  
# on rattache ensuite les tables à une metadata

metadata = MetaData()

computers_table = Table('computers',metadata,
                  Column('computer_id',Integer, primary_key=True),
                  Column('date_achat',Date) ,
                  Column('marque',Unicode(20)),
                  Column('qte',Float),
                  Column('prix',Float),)

os_table = Table('os',metadata,
                  Column('os_id',Integer, primary_key=True),
                  Column('computer_id', None, ForeignKey( 
'computers.computer_id')),
                  Column('os',Unicode(20)),)


# création des tables
metadata.create_all(engine)

# liste de dictionnaire pour mise à jour
liste_computers = [{'date_achat':'2007-03-05',
                    'marque':'M4',
                    'qte':1000,
                    'prix':35.14},
                   {'date_achat':'2007-04-05',
                    'marque':'M3',
                    'qte':10000,
                    'prix':40.143},
                   {'date_achat':'2007-03-05',
                    'marque':'M2',
                    'qte':20000,
                    'prix':40.14},
                   {'date_achat':'2007-03-05',
                    'marque':'M1',
                    'qte':10000,
                    'prix':35.1}]

liste_os = [ {'computer_id':'1','nom_os':'Linux'},
             {'computer_id':'2','nom_os':'Linux'},
             {'computer_id':'3','nom_os':'windows'}]

# création d'une connexion à la base
conn = engine.connect()

# insertion

conn.execute(computers_table.insert(),liste_computers)
conn.execute(os_table.insert(),liste_os)


# Explicit, connection
result_os=conn.execute(os_table.select())
pprint(result_os.fetchall())

# Explicit, connectionless

result_os = engine.execute(os_table.select())
pprint(result_os.fetchall())

# Implicite Connectionless
metadata.bind = engine
result_os=os_table.select().execute()
pprint(result_os.fetchall())

ordinateurs = computers_table.select(computers_table.c.prix < 
100.0).execute()
ordinateur_pas_cher  = ordinateurs.fetchone()
print ("marque d'un ordi pas cher: %s ") % ordinateur_pas_cher.marque

ordinateurs = computers_table.select(and_((computers_table.c.prix > 
1000.0),(computers_table.c.prix > 1000.0))).execute()
ordinateur_medium_price  = ordinateurs.fetchone()
print ("marque d'un ordi medium price: %s ") % ordinateur_pas_cher.marque

ordinateurs = 
select([computers_table.c.marque,computers_table.c.prix]).execute()
for ordi in ordinateurs:
    print "marque:%s prix:%s" % (ordi[0],ordi[1])

result_os.close()
ordinateurs.close()

metadata.bind = None
conn.close()

# nettoyage drop des tables
engine.drop(os_table)
#engine.drop(computers_table)
#os_table.drop(bind=conn)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to