示例#1
0
        public static List <RdbField> RetrieveMySqlTableFields(String databaseType, String tableName)
        {
            List <RdbField> fieldNames = new List <RdbField>();

            DataConnector dataConnector = new DataConnector();

            dataConnector.OpenConnection(databaseType);

            String          query      = "SELECT * FROM information_schema.columns WHERE table_schema = 'addoncontratos' AND table_name = '" + tableName + "'";
            MySqlCommand    command    = new MySqlCommand(query, dataConnector.MySqlConnection);
            MySqlDataReader dataReader = command.ExecuteReader();

            while (dataReader.Read())
            {
                String columnInfo = ((String)dataReader["COLUMN_TYPE"]).Trim();
                columnInfo = columnInfo.Replace(((String)dataReader["DATA_TYPE"]).Trim(), "");
                columnInfo = columnInfo.Replace("(", "");
                columnInfo = columnInfo.Replace(")", "");
                short columnLenght = 0;
                short.TryParse(columnInfo, out columnLenght);

                RdbField field = new RdbField();
                field.name = ((String)dataReader["COLUMN_NAME"]).Trim();
                field.type = ((String)dataReader["DATA_TYPE"]).Trim();
                field.size = columnLenght;

                fieldNames.Add(field);
            }
            dataReader.Close();

            dataConnector.CloseConnection();

            return(fieldNames);
        }
示例#2
0
        public static List <RdbField> RetrieveFirebirdTableFields(String databaseType, String tableName)
        {
            List <RdbField> fieldNames = new List <RdbField>();

            DataConnector dataConnector = new DataConnector();

            dataConnector.OpenConnection(databaseType);

            String query = "SELECT R.RDB$FIELD_NAME, T.RDB$TYPE_NAME, F.RDB$FIELD_LENGTH, R.RDB$NULL_FLAG " +
                           "FROM RDB$RELATION_FIELDS R, RDB$TYPES T, RDB$FIELDS F " +
                           "WHERE R.RDB$RELATION_NAME = '" + tableName + "' AND " +
                           "F.RDB$FIELD_NAME = R.RDB$FIELD_SOURCE AND " +
                           "T.RDB$FIELD_NAME = 'RDB$FIELD_TYPE' AND " +
                           "F.RDB$FIELD_TYPE = T.RDB$TYPE";

            FbCommand    command    = new FbCommand(query, dataConnector.FirebirdConnection);
            FbDataReader dataReader = command.ExecuteReader();

            while (dataReader.Read())
            {
                RdbField field = new RdbField();
                field.name = ((String)dataReader["RDB$FIELD_NAME"]).Trim();
                field.type = ((String)dataReader["RDB$TYPE_NAME"]).Trim();
                field.size = (short)dataReader["RDB$FIELD_LENGTH"];

                fieldNames.Add(field);
            }
            dataReader.Close();

            dataConnector.CloseConnection();

            return(fieldNames);
        }