我正在尝试使用Python SQLAlchemy将MS SQL Server视图反映到SQLite表中。
问题是sqlalchemy将COLLATE“ SQL_Latin1_General_CP1_CI_AS”添加到各种NVARCHAR列,而sqlite不支持。
是否存在从表定义中删除所有COLLATES的与列名无关的方法?
int limit = 15;
for(int i = 1; i < limit; i++) {
String textView = "setting" + i;
if(holder.textView.getLineCount() == 0) {
holder.textView.setVisibility(View.GONE);
}
}
我收到以下错误:
from sqlalchemy import *
from sqlalchemy.orm import create_session
from sqlalchemy.ext.declarative import declarative_base
import urllib
from sqlalchemy.orm import sessionmaker
#Create and engine and get the metadata
Base = declarative_base()
source_connection = 'msql+pyodbc...'
source_engine = create_engine(source_connection)
metadata = MetaData(bind=source_engine)
SourceSession = sessionmaker(source_engine)
#destination
dest_engine = create_engine('sqlite:///...', echo=True)
DestSession = sessionmaker(dest_engine)
#Reflect each database table we need to use, using metadata
class tblR(Base):
__table__ = Table('tblR', metadata,
Column("r_id", Integer, primary_key=True),
autoload=True)
#Create a session to use the tables
# This is the query we want to persist in a new table:
sourceSession = SourceSession()
query= sourceSession.query(tblR.r_id, tblR.MK_Assumed).filter_by(r_id=0)
# Build the schema for the new table
# based on the columns that will be returned
# by the query:
metadata = MetaData(bind=dest_engine)
columns = [Column(desc['name'], desc['type']) for desc in query.column_descriptions]
column_names = [desc['name'] for desc in query.column_descriptions]
table = Table("newtable", metadata, *columns)
# Create the new table in the destination database
table.create(dest_engine)
# Finally execute the query
destSession = DestSession()
for row in query:
destSession.execute(table.insert(row))
destSession.commit()
答案 0 :(得分:1)
我遇到了类似的问题,这就是我解决它的方法:
for table in metadata.sorted_tables :
for col in table.c:
if getattr(col.type, 'collation', None) is not None:
col.type.collation = None
编辑:为了获得更明确的控制,您似乎可以指定'BINARY
','NOCASE'
或'RTRIM'