private void CreateColumns() { CSSchemaColumn[] columns = DB.GetSchemaColumns(TableName); _identityColumn = null; _columnList.Clear(); _keyColumnList.Clear(); foreach (var column in columns) { if (column.Hidden) { continue; } if (column.IsKey) { _keyColumnList.Add(column); } if (column.Identity) { _identityColumn = column; } _columnList.Add(column); } }
protected internal override CSSchemaColumn[] GetSchemaColumns(string tableName) { using (ICSDbConnection newConn = CreateConnection()) { ICSDbCommand dbCommand = newConn.CreateCommand(); dbCommand.CommandText = "select * from " + QuoteTable(tableName); using (var dataReader = (CSSqlReader)dbCommand.ExecuteReader(CSCommandBehavior.SchemaOnly | CSCommandBehavior.KeyInfo)) { var schemaColumns = new List <CSSchemaColumn>(); DataTable schemaTable = dataReader.Reader.GetSchemaTable(); bool hasHidden = schemaTable.Columns.Contains("IsHidden"); bool hasIdentity = schemaTable.Columns.Contains("IsIdentity"); bool hasAutoincrement = schemaTable.Columns.Contains("IsAutoIncrement"); foreach (DataRow schemaRow in schemaTable.Rows) { var schemaColumn = new CSSchemaColumn(); if (hasHidden && !schemaRow.IsNull("IsHidden") && (bool)schemaRow["IsHidden"]) { schemaColumn.Hidden = true; } if (hasIdentity && !schemaRow.IsNull("IsIdentity") && (bool)schemaRow["IsIdentity"]) { schemaColumn.Identity = true; } schemaColumn.IsKey = (bool)schemaRow["IsKey"]; schemaColumn.AllowNull = (bool)schemaRow["AllowDBNull"]; schemaColumn.Name = (string)schemaRow["ColumnName"]; schemaColumn.ReadOnly = (bool)schemaRow["IsReadOnly"]; schemaColumn.DataType = (Type)schemaRow["DataType"]; schemaColumn.Size = (int)schemaRow["ColumnSize"]; if (hasAutoincrement && !schemaRow.IsNull("IsAutoIncrement") && (bool)schemaRow["IsAutoIncrement"]) { schemaColumn.Identity = true; } schemaColumns.Add(schemaColumn); } return(schemaColumns.ToArray()); } } }
internal CSSchemaField(CSSchemaColumn schemaColumn , CSSchema schema) { _schema = schema; _mappedColumn = schemaColumn; //if (schemaColumn.DataType == typeof(byte[])) // _lazy = true; schemaColumn.MappedField = this; _fieldType = MappedColumn.DataType; _realType = _fieldType.Inspector().RealType; }
internal CSSchemaField(CSSchemaColumn schemaColumn, CSSchema schema) { _schema = schema; _mappedColumn = schemaColumn; //if (schemaColumn.DataType == typeof(byte[])) // _lazy = true; schemaColumn.MappedField = this; _fieldType = MappedColumn.DataType; _realType = _fieldType.Inspector().RealType; }
internal void FromDataReader(ICSDbReader dataReader, Dictionary <string, string> aliasMap) { for (int i = 0; i < dataReader.FieldCount; i++) { string aliasName = dataReader.GetName(i); string fieldName; if (aliasMap == null) { fieldName = aliasName; } else if (!aliasMap.TryGetValue(aliasName, out fieldName)) { continue; } CSSchemaColumn schemaColumn = _schema.Columns[fieldName]; if (schemaColumn == null || schemaColumn.Hidden) { continue; } object columnValue = dataReader[i]; if (columnValue == _schema.DB.NullFieldValue()) { columnValue = null; } if (schemaColumn.MappedField.Trim && columnValue is string) { columnValue = ((string)columnValue).Trim(); } CSFieldValue fieldValue = _fieldData["#" + schemaColumn.Name]; fieldValue.ValueDirect = columnValue; fieldValue.ValueState = CSFieldValueState.Read; } _dataState = CSObjectDataState.Loaded; }
protected internal override CSSchemaColumn[] GetSchemaColumns(string tableName) { using (ICSDbConnection newConn = CreateConnection()) { List <CSSchemaColumn> columns = new List <CSSchemaColumn>(); DataTable schemaTable = ((CSSqliteConnection)newConn).GetSchema(tableName); bool hasHidden = schemaTable.Columns.Contains("IsHidden"); bool hasIdentity = schemaTable.Columns.Contains("IsIdentity"); bool hasAutoincrement = schemaTable.Columns.Contains("IsAutoIncrement"); foreach (DataRow schemaRow in schemaTable.Rows) { CSSchemaColumn schemaColumn = new CSSchemaColumn(); if (hasHidden && !schemaRow.IsNull("IsHidden") && (bool)schemaRow["IsHidden"]) { schemaColumn.Hidden = true; } schemaColumn.IsKey = (bool)schemaRow["IsKey"]; schemaColumn.AllowNull = (bool)schemaRow["AllowDBNull"]; schemaColumn.Name = (string)schemaRow["ColumnName"]; schemaColumn.ReadOnly = (bool)schemaRow["IsReadOnly"]; schemaColumn.DataType = (Type)schemaRow["DataType"]; schemaColumn.Size = (int)schemaRow["ColumnSize"]; if (hasAutoincrement && !schemaRow.IsNull("IsAutoIncrement") && (bool)schemaRow["IsAutoIncrement"]) { schemaColumn.Identity = true; } if (hasIdentity && !schemaRow.IsNull("IsIdentity") && (bool)schemaRow["IsIdentity"]) { schemaColumn.Identity = true; } columns.Add(schemaColumn); } return(columns.ToArray()); } }
private void CreateColumns() { CSSchemaColumn[] columns = DB.GetSchemaColumns(TableName); _identityColumn = null; _columnList.Clear(); _keyColumnList.Clear(); foreach (var column in columns) { if (column.Hidden) continue; if (column.IsKey) _keyColumnList.Add(column); if (column.Identity) _identityColumn = column; _columnList.Add(column); } }
protected internal override CSSchemaColumn[] GetSchemaColumns(string tableName) { List<string> autoColumns = new List<string>(); using ( CSSqliteCommand cmd = (CSSqliteCommand) CreateCommand("select sql from sqlite_master where type='table' and name=@tablename", new CSParameterCollection("@tablename", tableName))) { string sql = (string) cmd.Command.ExecuteScalar(); Regex regex = new Regex(@"[\(,]\s*(?<column>[a-z0-9_]+).*?AUTOINCREMENT", RegexOptions.IgnoreCase); Match m = regex.Match(sql); if (m.Success) { autoColumns.Add(m.Groups["column"].Value.ToUpper()); } } List<CSSchemaColumn> columns = new List<CSSchemaColumn>(); using (CSSqliteCommand cmd = (CSSqliteCommand) CreateCommand("pragma table_info (" + tableName + ")", null)) { using (CSSqliteReader reader = (CSSqliteReader) cmd.ExecuteReader()) { while (reader.Read()) { CSSchemaColumn column = new CSSchemaColumn(); string columnName = (string) reader.Reader["name"]; column.Name = columnName; column.IsKey = reader.Reader["pk"].Convert<bool>(); column.AllowNull = !reader.Reader["notnull"].Convert<bool>(); column.ReadOnly = false; column.Size = 1000; Type dataType = null; string dbType = (string) reader.Reader["type"]; int paren = dbType.IndexOf('('); if (paren > 0) dbType = dbType.Substring(0, paren); dbType = dbType.ToUpper(); switch (dbType) { case "TEXT": dataType = typeof (string); break; case "VARCHAR": dataType = typeof (string); break; case "INTEGER": dataType = typeof (int); break; case "BOOL": dataType = typeof (bool); break; case "DOUBLE": dataType = typeof (double); break; case "FLOAT": dataType = typeof (double); break; case "REAL": dataType = typeof (double); break; case "CHAR": dataType = typeof (string); break; case "BLOB": dataType = typeof (byte[]); break; case "NUMERIC": dataType = typeof (decimal); break; case "DATETIME": dataType = typeof (DateTime); break; } column.DataType = dataType; column.Identity = autoColumns.Contains(columnName.ToUpper()); columns.Add(column); } } return columns.ToArray(); } }
protected override CSSchemaColumn[] GetSchemaColumns(string tableName) { using (ICSDbConnection newConn = CreateConnection()) { ICSDbCommand dbCommand = newConn.CreateCommand(); dbCommand.CommandText = "select * from " + QuoteTable(tableName); using (CSOracleReader dataReader = (CSOracleReader)dbCommand.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo)) { List<CSSchemaColumn> columns = new List<CSSchemaColumn>(); DataTable schemaTable = dataReader.Reader.GetSchemaTable(); bool hasHidden = schemaTable.Columns.Contains("IsHidden"); bool hasIdentity = schemaTable.Columns.Contains("IsIdentity"); bool hasAutoincrement = schemaTable.Columns.Contains("IsAutoIncrement"); foreach (DataRow schemaRow in schemaTable.Rows) { CSSchemaColumn schemaColumn = new CSSchemaColumn(); if (hasHidden && !schemaRow.IsNull("IsHidden") && (bool)schemaRow["IsHidden"]) schemaColumn.Hidden = true; schemaColumn.IsKey = (bool)schemaRow["IsKey"]; schemaColumn.AllowNull = (bool)schemaRow["AllowDBNull"]; schemaColumn.Name = (string)schemaRow["ColumnName"]; schemaColumn.ReadOnly = (bool)schemaRow["IsReadOnly"]; schemaColumn.DataType = (Type)schemaRow["DataType"]; schemaColumn.Size = (int)schemaRow["ColumnSize"]; if (hasAutoincrement && !schemaRow.IsNull("IsAutoIncrement") && (bool)schemaRow["IsAutoIncrement"]) schemaColumn.Identity = true; if (hasIdentity && !schemaRow.IsNull("IsIdentity") && (bool)schemaRow["IsIdentity"]) schemaColumn.Identity = true; columns.Add(schemaColumn); } return columns.ToArray(); } } }
protected internal override CSSchemaColumn[] GetSchemaColumns(string tableName) { using (ICSDbConnection newConn = CreateConnection()) { List<CSSchemaColumn> columns = new List<CSSchemaColumn>(); DataTable schemaTable = ((CSSqliteConnection)newConn).GetSchema(tableName); bool hasHidden = schemaTable.Columns.Contains("IsHidden"); bool hasIdentity = schemaTable.Columns.Contains("IsIdentity"); bool hasAutoincrement = schemaTable.Columns.Contains("IsAutoIncrement"); foreach (DataRow schemaRow in schemaTable.Rows) { CSSchemaColumn schemaColumn = new CSSchemaColumn(); if (hasHidden && !schemaRow.IsNull("IsHidden") && (bool)schemaRow["IsHidden"]) schemaColumn.Hidden = true; schemaColumn.IsKey = (bool)schemaRow["IsKey"]; schemaColumn.AllowNull = (bool)schemaRow["AllowDBNull"]; schemaColumn.Name = (string)schemaRow["ColumnName"]; schemaColumn.ReadOnly = (bool)schemaRow["IsReadOnly"]; schemaColumn.DataType = (Type)schemaRow["DataType"]; schemaColumn.Size = (int)schemaRow["ColumnSize"]; if (hasAutoincrement && !schemaRow.IsNull("IsAutoIncrement") && (bool)schemaRow["IsAutoIncrement"]) schemaColumn.Identity = true; if (hasIdentity && !schemaRow.IsNull("IsIdentity") && (bool)schemaRow["IsIdentity"]) schemaColumn.Identity = true; columns.Add(schemaColumn); } return columns.ToArray(); } }
internal CSSchemaField(PropertyInfo propInfo , CSSchema schema) { _propertyInfo = propInfo; _schema = schema; _fieldType = _propertyInfo.PropertyType; _realType = _fieldType.Inspector().RealType; RelationAttribute attRelation = (RelationAttribute) Attribute.GetCustomAttribute(propInfo,typeof(RelationAttribute),true); _prefetch = propInfo.IsDefined(typeof(PrefetchAttribute), true); if (attRelation != null) { _relation = new CSRelation(schema,attRelation); return; } _lazy = propInfo.IsDefined(typeof(LazyAttribute) , true); _noCreate = propInfo.IsDefined(typeof(NoCreateAttribute) , true); _trim = propInfo.IsDefined(typeof(TrimAttribute), true); _optimisticLock = propInfo.IsDefined(typeof(OptimisticLockAttribute), true); _clientGenerated = propInfo.IsDefined(typeof(ClientGeneratedAttribute), true); _serverGenerated = propInfo.IsDefined(typeof(ServerGeneratedAttribute), true); _notMapped = propInfo.IsDefined(typeof (NotMappedAttribute), true); MapToAttribute attMapTo = (MapToAttribute) Attribute.GetCustomAttribute(propInfo,typeof(MapToAttribute),true); NullValueAttribute attNull = (NullValueAttribute) Attribute.GetCustomAttribute(propInfo,typeof(NullValueAttribute),true); IdentityAttribute attIdentity = (IdentityAttribute)Attribute.GetCustomAttribute(propInfo, typeof(IdentityAttribute), true); if (!_notMapped) { if (CSConfig.ColumnMappingOverrideMap.ContainsValue(propInfo.DeclaringType.Name + ":" + propInfo.Name)) _mappedColumn = schema.Columns[ CSConfig.ColumnMappingOverrideMap[propInfo.DeclaringType.Name + ":" + propInfo.Name]]; else if (attMapTo != null) _mappedColumn = schema.Columns[attMapTo.Name]; else _mappedColumn = schema.Columns[propInfo.Name]; if (_mappedColumn != null) _mappedColumn.MappedField = this; } SequenceAttribute sequenceAttribute = (SequenceAttribute) Attribute.GetCustomAttribute(propInfo,typeof(SequenceAttribute), true); if (sequenceAttribute != null && _schema.DB.SupportsSequences) { _sequenceName = sequenceAttribute.SequenceName; if (_mappedColumn != null && sequenceAttribute.Identity) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (attIdentity != null) { if (_mappedColumn != null) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (attNull != null) { _nullValue = attNull.NullValue; } else { Type fieldType = FieldType; if (fieldType == typeof(string)) _nullValue = String.Empty; else if (fieldType.IsValueType) _nullValue = Activator.CreateInstance(fieldType); } if (_mappedColumn != null && _mappedColumn.ReadOnly) { if (_propertyInfo.CanWrite) throw new CSException("Property [" + Name + "] for class [" + _schema.ClassType.Name + "] should be read-only"); } }
internal CSSchemaField(PropertyInfo propInfo, CSSchema schema) { _propertyInfo = propInfo; _schema = schema; _fieldType = _propertyInfo.PropertyType; _realType = _fieldType.Inspector().RealType; RelationAttribute attRelation = propInfo.GetCustomAttribute <RelationAttribute>(true); _prefetch = propInfo.IsDefined(typeof(PrefetchAttribute), true); if (attRelation != null) { _relation = new CSRelation(schema, attRelation); return; } _lazy = propInfo.IsDefined(typeof(LazyAttribute), true); _noCreate = propInfo.IsDefined(typeof(NoCreateAttribute), true); _trim = propInfo.IsDefined(typeof(TrimAttribute), true); _optimisticLock = propInfo.IsDefined(typeof(OptimisticLockAttribute), true); _clientGenerated = propInfo.IsDefined(typeof(ClientGeneratedAttribute), true); _serverGenerated = propInfo.IsDefined(typeof(ServerGeneratedAttribute), true); _notMapped = propInfo.IsDefined(typeof(NotMappedAttribute), true); var mapToAttribute = propInfo.GetCustomAttribute <MapToAttribute>(true); var nullValueAttribute = propInfo.GetCustomAttribute <NullValueAttribute>(true); var identityAttribute = propInfo.GetCustomAttribute <IdentityAttribute>(true); if (!_notMapped) { if (CSConfig.ColumnMappingOverrideMap.ContainsValue(propInfo.DeclaringType.Name + ":" + propInfo.Name)) { _mappedColumn = schema.Columns[ CSConfig.ColumnMappingOverrideMap[propInfo.DeclaringType.Name + ":" + propInfo.Name]]; } else if (mapToAttribute != null) { _mappedColumn = schema.Columns[mapToAttribute.Name]; } else { _mappedColumn = schema.Columns[propInfo.Name]; } if (_mappedColumn != null) { _mappedColumn.MappedField = this; } } var sequenceAttribute = propInfo.GetCustomAttribute <SequenceAttribute>(true); if (sequenceAttribute != null && _schema.DB.SupportsSequences) { _sequenceName = sequenceAttribute.SequenceName; if (_mappedColumn != null && sequenceAttribute.Identity) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (identityAttribute != null) { if (_mappedColumn != null) { _mappedColumn.Identity = true; _schema.IdentityColumn = _mappedColumn; } } if (nullValueAttribute != null) { _nullValue = nullValueAttribute.NullValue; } else { Type fieldType = FieldType; if (fieldType == typeof(string)) { _nullValue = String.Empty; } else if (fieldType.GetTypeInfo().IsValueType) { _nullValue = Activator.CreateInstance(fieldType); } } if (_mappedColumn != null && _mappedColumn.ReadOnly) { if (_propertyInfo.CanWrite) { throw new CSException("Property [" + Name + "] for class [" + _schema.ClassType.Name + "] should be read-only"); } } }
private void CreateColumns() { if (DB == null) { throw new InvalidOperationException("CSSchema: CreateColumns - DB not initialized"); } CSSchemaColumn[] columns = DB.GetSchemaColumns(TableName); // DataTable schemaTable = DB.GetSchemaTable(TableName); _identityColumn = null; _columnList.Clear(); _keyColumnList.Clear(); /* bool hasHidden = schemaTable.Columns.Contains("IsHidden"); bool hasIdentity = schemaTable.Columns.Contains("IsIdentity"); bool hasAutoincrement = schemaTable.Columns.Contains("IsAutoIncrement"); */ foreach (var column in columns) { if (column.IsKey) _keyColumnList.Add(column); if (column.Identity) _identityColumn = column; _columnList.Add(column); } }
private void CreateColumns() { CSSchemaColumn[] columns = DB.GetSchemaColumns(TableName); // DataTable schemaTable = DB.GetSchemaTable(TableName); _identityColumn = null; _columnList.Clear(); _keyColumnList.Clear(); /* bool hasHidden = schemaTable.Columns.Contains("IsHidden"); bool hasIdentity = schemaTable.Columns.Contains("IsIdentity"); bool hasAutoincrement = schemaTable.Columns.Contains("IsAutoIncrement"); */ foreach (var column in columns) { if (column.IsKey) _keyColumnList.Add(column); if (column.Identity) _identityColumn = column; _columnList.Add(column); } }