[repository] #1460066: backport datafeed cube as cubicweb source
* add some attributes to CWSource to handle this kind of source
(not natural to put everything in 'config' string). Adding a CWSource
subclass has been attempted then rollbacked because it adds pain
to handle multi-sources planning and it introduce an ambiguity on
a generic relation (cw_source), which may be a penalty in multiple
case
* data feed sources are a new kind of source, namely 'copy based',
which have no effect on the query planner
* a data feed source is associated to a list of url and a parser (appobjects
in the 'parsers' registry
* entities imported by a data feed have cwuri set to their url on the distant
site, their cw_source relation point to the data feed source, though their
source stored in the entities table (returned by cw_metainformation) is their
physical source, hence 'system'
defmigrate_varchar_to_nvarchar():dbdriver=config.sources()['system']['db-driver']ifdbdriver!="sqlserver2005":returnintrospection_sql="""\SELECT table_schema, table_name, column_name, is_nullable, character_maximum_lengthFROM information_schema.columnsWHERE data_type = 'VARCHAR' and table_name <> 'SYSDIAGRAMS'"""has_index_sql="""\SELECT i.name AS index_name, i.type_desc, i.is_unique, i.is_unique_constraintFROM sys.indexes AS i, sys.index_columns as j, sys.columns as kWHERE is_hypothetical = 0 AND i.index_id <> 0AND i.object_id = j.object_idAND i.index_id = j.index_idAND i.object_id = OBJECT_ID('%(table)s')AND k.name = '%(col)s'AND k.object_id=i.object_idAND j.column_id = k.column_id;"""generated_statements=[]forschema,table,column,is_nullable,lengthinsql(introspection_sql,ask_confirm=False):qualified_table='[%s].[%s]'%(schema,table)rset=sql(has_index_sql%{'table':qualified_table,'col':column},ask_confirm=False)drops=[]creates=[]foridx_name,idx_type,idx_unique,is_unique_constraintinrset:ifis_unique_constraint:drops.append('ALTER TABLE %s DROP CONSTRAINT %s'%(qualified_table,idx_name))creates.append('ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s)'%(qualified_table,idx_name,column))else:drops.append('DROP INDEX %s ON %s'%(idx_name,qualified_table))ifidx_unique:unique='UNIQUE'else:unique=''creates.append('CREATE %s%s INDEX %s ON %s(%s)'%(unique,idx_type,idx_name,qualified_table,column))iflength==-1:length='max'ifis_nullable=='YES':not_null='NULL'else:not_null='NOT NULL'alter_sql='ALTER TABLE %s ALTER COLUMN %s NVARCHAR(%s) %s'%(qualified_table,column,length,not_null)generated_statements+=drops+[alter_sql]+createsforstatementingenerated_statements:printstatementsql(statement,ask_confirm=False)commit()migrate_varchar_to_nvarchar()