使用PyQt和QulAlchemy和Qalchemy的Imt接受QStrings。 是否有办法把QStrings传给它,或者我不得不将QStrings转换成每一次的掩体?
谢谢。
该法典:
import sip
sip.setapi( QString , 2)
from sqlalchemy import create_engine
from sqlalchemy import Table, Column, Integer, String, Float, MetaData, ForeignKey
from sqlalchemy.sql import select, and_
from PyQt4 import QtGui, QtCore
class DbUtils(object):
def __init__(self, db_file = None, parent = None):
self.db = None
self.db_connection = None
self.db_file = str(db_file)
def db_open(self):
self.db = create_engine( sqlite:/// + self.db_file)
self.db_connection = self.db.connect()
def db_close(self):
self.db_connection.close()
def db_create_voltdrop(self):
metadata = MetaData()
tb_cable_brands = Table( cable_brands , metadata,
Column( id , Integer, primary_key=True),
Column( brand , String)
)
tb_cable_types = Table( cable_types , metadata,
Column( id , Integer, primary_key=True),
Column( brand_id , None, ForeignKey( cable_brands.id )),
Column( type , String),
Column( alpha , String)
)
tb_cable_data = Table( cable_data , metadata,
Column( id , Integer, primary_key=True),
Column( type_id , None, ForeignKey( cable_types.id )),
Column( size , String),
Column( resistance , Float)
)
metadata.create_all(self.db)
def delete_cable_brand(self, cable_brand):
cable_brand = str(cable_brand)
metadata = MetaData()
metadata.bind = self.db
tb_cable_brands = Table( cable_brands , metadata, autoload = True)
cable_brands = select([tb_cable_brands.c.brand],
and_(tb_cable_brands.c.brand == cable_brand)
)
row = self.db_connection.execute(cable_brands)
data = row.fetchone()
if str(data[0]) == cable_brand:
cable_brands = tb_cable_brands.delete().where(tb_cable_brands.c.brand == cable_brand)
self.db_connection.execute(cable_brands)
return True
else:
return False