Re: utilitaire de conversion de scrip sql

From: "Norbert Saint Georges" <Norbert(dot)Saint-Georges(at)generation-eco(dot)com>
To: <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Re: utilitaire de conversion de scrip sql
Date: 2012-12-15 12:07:41
Message-ID: 8534997D52846E4CA436A90A7140ABB055C0@database.ge.local
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

Merci pour vos réponses.

Effectivement je parlais de mssql :-)

Je vais le coder moi-même, je par du principe que toute les valeurs dont j'ai besoin se trouve dans les tables sys.

Du genre ( pour une DB 2005) :

select objects.name as ObjectName

, objects.type as ObjectType

, columns.name as ColumnName

, columns.column_id as colid

, columns.system_type_id as xtype

, columns.system_type_id as type

, (case when columns.max_length = -1 then 1073741823

when columns.system_type_id = 231 then columns.max_length/2

when columns.system_type_id = 99 then 1073741823

else columns.max_length

end

) as length

, columns.max_length

, columns.precision as prec

, cast(0 as bit) as cdefault

, cast(0 as bit) as isoutparam

, (case when columns.system_type_id = 36 then N'uniqueidentifier'

when columns.system_type_id = 48 then N'tinyint'

when columns.system_type_id = 56 then N'int'

when columns.system_type_id = 52 then N'smallint'

when columns.system_type_id = 127 then N'bigint'

when columns.system_type_id = 59 then N'real'

when columns.system_type_id = 62 then N'float(' + cast(columns.precision as varchar) + N')'

when columns.system_type_id = 60 then N'money'

when columns.system_type_id = 104 then N'bit'

when columns.system_type_id = 175 then N'char(' + cast(columns.max_length as varchar) + N')'

when columns.system_type_id = 167 then N'varchar(' + (case max_length when -1 then '8000' else cast(columns.max_length as varchar) end) + N')'

when columns.system_type_id = 231 then N'varchar(' + (case max_length when -1 then '8000' else cast(columns.max_length/2 as varchar) end) + N')'

when columns.system_type_id = 239 then N'char(' + cast(columns.max_length/2 as varchar) + N')'

when columns.system_type_id = 35 then N'text'

when columns.system_type_id = 99 then N'text'

when columns.system_type_id = 61 then N'datetime'

when columns.system_type_id = 34 then N'image'

when columns.system_type_id = 106 then N'decimal(' + cast(columns.precision as varchar) + N', ' + cast(columns.scale as varchar) + N')'

when columns.system_type_id = 108 then N'decimal(' + cast(columns.precision as varchar) + N', ' + cast(columns.scale as varchar) + N')'

when columns.system_type_id = 165 then N'varbinary('+ (case max_length when -1 then 'max' else cast(columns.max_length as varchar) end) + N')'

when columns.system_type_id = 173 then N'binary(' + cast(columns.max_length as varchar) + N')'

when columns.system_type_id = 189 then N'timestamp'

end

) as ColumnType

, (case when columns.system_type_id = 36 then N'SqlDbType.UniqueIdentifier'

when columns.system_type_id = 48 then N'SqlDbType.TinyInt'

when columns.system_type_id = 56 then N'SqlDbType.Int'

when columns.system_type_id = 52 then N'SqlDbType.SmallInt'

when columns.system_type_id = 127 then N'SqlDbType.BigInt'

when columns.system_type_id = 59 then N'SqlDbType.Real'

when columns.system_type_id = 62 then N'SqlDbType.Real'

when columns.system_type_id = 60 then N'SqlDbType.Money'

when columns.system_type_id = 104 then N'SqlDbType.Bit'

when columns.system_type_id = 175 then N'SqlDbType.Char'

when columns.system_type_id = 167 then N'SqlDbType.VarChar'

when columns.system_type_id = 231 then N'SqlDbType.NVarChar'

when columns.system_type_id = 239 then N'SqlDbType.NChar'

when columns.system_type_id = 35 then N'SqlDbType.Text'

when columns.system_type_id = 99 then N'SqlDbType.NText'

when columns.system_type_id = 61 then N'SqlDbType.DateTime'

when columns.system_type_id = 34 then N'SqlDbType.VarBinary'

when columns.system_type_id = 106 then N'SqlDbType.Real'

when columns.system_type_id = 108 then N'SqlDbType.Real'

when columns.system_type_id = 165 then N'SqlDbType.VarBinary'

when columns.system_type_id = 173 then N'SqlDbType.Binary'

when columns.system_type_id = 189 then N'SqlDbType.TimeStamp'

end

) as SqlDbType

, (case when columns.system_type_id = 36 then N'Guid'

when columns.system_type_id = 48 then N'short'

when columns.system_type_id = 56 then N'Int32'

when columns.system_type_id = 52 then N'Int16'

when columns.system_type_id = 127 then N'Int64'

when columns.system_type_id = 59 then N'float'

when columns.system_type_id = 62 then N'float'

when columns.system_type_id = 60 then N'decimal'

when columns.system_type_id = 104 then N'bool'

when columns.system_type_id = 175 then N'ansistring'

when columns.system_type_id = 167 then N'ansistring'

when columns.system_type_id = 231 then N'string'

when columns.system_type_id = 239 then N'string'

when columns.system_type_id = 35 then N'string'

when columns.system_type_id = 99 then N'string'

when columns.system_type_id = 61 then N'DateTime'

when columns.system_type_id = 34 then N'byte[]'

when columns.system_type_id = 106 then N'float'

when columns.system_type_id = 108 then N'float'

when columns.system_type_id = 165 then N'byte[]'

when columns.system_type_id = 173 then N'byte[]'

when columns.system_type_id = 189 then N'TimeStamp'

end

) as CsType

, (case when columns.system_type_id = 36 then N'g'

when columns.system_type_id = 48 then N'n'

when columns.system_type_id = 56 then N'n'

when columns.system_type_id = 52 then N'n'

when columns.system_type_id = 127 then N'l'

when columns.system_type_id = 59 then N'fl'

when columns.system_type_id = 62 then N'fl'

when columns.system_type_id = 60 then N'd'

when columns.system_type_id = 104 then N'b'

when columns.system_type_id = 175 then N's'

when columns.system_type_id = 167 then N's'

when columns.system_type_id = 231 then N's'

when columns.system_type_id = 239 then N's'

when columns.system_type_id = 35 then N's'

when columns.system_type_id = 99 then N's'

when columns.system_type_id = 61 then N'dt'

when columns.system_type_id = 34 then N'by'

when columns.system_type_id = 106 then N'fl'

when columns.system_type_id = 108 then N'fl'

when columns.system_type_id = 165 then N'bin'

when columns.system_type_id = 173 then N'bin'

when columns.system_type_id = 189 then N'ts'

end

) as CsPrefix

, columns.is_identity as IsIdentity

, columns.is_nullable as IsNullable

from sys.objects objects

inner join sys.columns columns

on columns.object_id = objects.object_id

where objects.name <> 'dtproperties'

and objects.type in ('U', 'V')

and objects.name = :TableName

Cela vous semblent logique comme point de départ ?

Maintenant, je cherche un tableau « valide » des correspondances pour Npgsql.

Cordialement

Norbert Saint Georges

Six Sigma Business Intelligence Analyst

Generation ECO sprl

In response to

Browse pgsql-fr-generale by date

  From Date Subject
Next Message mtcocktail 2012-12-18 14:23:49 escape string et postgres9.1
Previous Message Cédric Villemain 2012-12-14 17:16:22 Re: utilitaire de conversion de scrip sql