1 #region MIT license 2 // 3 // MIT license 4 // 5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 // 25 #endregion 26 using System; 27 using System.Collections.Generic; 28 using System.Data; 29 using System.Linq; 30 using System.Text; 31 using DbLinq.Util; 32 using DbLinq.Vendor; 33 34 namespace DbLinq.Firebird 35 { 36 partial class FirebirdSchemaLoader 37 { ReadColumn(IDataReader rdr)38 protected virtual IDataTableColumn ReadColumn(IDataReader rdr) 39 { 40 var column = new DataTableColumn(); 41 int field = 0; 42 column.TableSchema = rdr.GetAsString(field++); 43 column.TableName = rdr.GetAsString(field++).Trim(); 44 column.ColumnName = rdr.GetAsString(field++).Trim(); 45 column.Nullable = rdr.GetAsBool(field++); 46 column.SqlType = rdr.GetAsString(field++).Trim(); 47 column.Generated = rdr.GetAsBool(field++); 48 //column.Unsigned = column.FullType.Contains("unsigned"); 49 column.PrimaryKey = rdr.GetAsBool(field++); 50 column.Length = rdr.GetAsNullableNumeric<long>(field++); 51 column.Precision = rdr.GetAsNullableNumeric<int>(field++); 52 column.Scale = rdr.GetAsNullableNumeric<int>(field++); 53 column.DefaultValue = rdr.GetAsString(field++); 54 FormatFullType(column); 55 return column; 56 } 57 FormatFullType(DataTableColumn column)58 private void FormatFullType(DataTableColumn column) 59 { 60 // TODO: Implement. 61 } 62 ReadColumns(IDbConnection connectionString, string databaseName)63 protected override IList<IDataTableColumn> ReadColumns(IDbConnection connectionString, string databaseName) 64 { 65 const string sql = @" 66 select 'Foo' ""TableSchema"" 67 , rf.RDB$RELATION_NAME ""TableName"" 68 , rf.RDB$FIELD_NAME ""ColumnName"" 69 , case when rf.RDB$NULL_FLAG is null then 1 else 0 end ""Nullable"" 70 , t.RDB$TYPE_NAME ""Type"" 71 , case when f.RDB$COMPUTED_SOURCE is null then 0 else 1 end ""Generated"" 72 , case when exists(select * 73 from RDB$RELATION_CONSTRAINTS rc 74 inner join RDB$INDEX_SEGMENTS xs on xs.RDB$INDEX_NAME = rc.RDB$INDEX_NAME 75 where rc.RDB$RELATION_NAME = rf.RDB$RELATION_NAME and xs.RDB$FIELD_NAME = rf.RDB$FIELD_NAME 76 and rc.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY') then 1 else 0 end ""PrimaryKey"" 77 , f.RDB$FIELD_LENGTH ""Length"" 78 , f.RDB$FIELD_PRECISION ""Precision"" 79 , f.RDB$FIELD_SCALE ""Scale"" 80 , rf.RDB$DEFAULT_VALUE ""DefaultValue"" 81 from RDB$RELATION_FIELDS rf 82 inner join RDB$FIELDS f on f.RDB$FIELD_NAME = rf.RDB$FIELD_SOURCE 83 inner join RDB$TYPES t on t.RDB$TYPE = f.RDB$FIELD_TYPE and t.RDB$FIELD_NAME = 'RDB$FIELD_TYPE' 84 where rf.RDB$SYSTEM_FLAG = 0 85 order by rf.RDB$RELATION_NAME, rf.RDB$FIELD_POSITION 86 "; 87 88 return DataCommand.Find<IDataTableColumn>(connectionString, sql, "@db", databaseName, ReadColumn); 89 } 90 } 91 } 92