michelc Blog

Just <strong>another</strong> WordPress.com weblog

Archive for octobre 2005

Convertir un type String en Enum

leave a comment »

enum EngineType {
	unknow, 
	access, 
	db2, 
	mysql, 
	odbc, 
	oledb, 
	oracle, 
	postgre, 
	sqlserver
}
string cnxTypeString = "mysql";
EngineType cnxTypeEngine = EngineType.unknow;
if (Enum.IsDefined(typeof(EngineType), cnxTypeString)) {
	cnxTypeEngine = (EngineType) Enum.Parse(typeof(EngineType), cnxTypeString, true);
}

(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/824)

Written by michel

20 octobre 2005 at 1:15

Publié dans c#, Code Snippets

Structure d’une table PostgreSQL depuis Information_Schema

leave a comment »

SELECT COLUMN_NAME,
       DATA_TYPE,
       CHARACTER_MAXIMUM_LENGTH,
       NUMERIC_PRECISION,
       NUMERIC_SCALE,
       IS_NULLABLE,
       SUBSTR(COALESCE(COLUMN_DEFAULT, '' ), 1, 8 ) = 'nextval(' AS IS_AUTOINCREMENT,
       COLUMN_DEFAULT
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  TABLE_NAME = 'xxxxxxxx'
ORDER BY ORDINAL_POSITION

(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/816)

Written by michel

18 octobre 2005 at 1:50

Publié dans Code Snippets, sql

leave a comment »

SELECT COLUMN_NAME,
       DATA_TYPE,
       CHARACTER_MAXIMUM_LENGTH,
       NUMERIC_PRECISION,
       NUMERIC_SCALE,
       IS_NULLABLE,
       COLUMNPROPERTY(OBJECT_ID(TABLE_NAME), COLUMN_NAME, 'IsIdentity') AS IS_AUTOINCREMENT,
       COLUMN_DEFAULT
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  TABLE_NAME = 'xxxxxxxx'
ORDER BY ORDINAL_POSITION

(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/815)

Edit : Voir aussi « system_function_schema.fn_datadictionary« , une fonction qui renvoie le dictionnaire de données pour n’importe quelle base Sql Server.

Written by michel

18 octobre 2005 at 1:45

Publié dans Code Snippets, sql