public void DecimalColumnWithCapacityAndPrecisionParsedToDecimal() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("Price", "Price", "decimal(10,2)", "price"); Assert.True(columnInfo.DbType == DbType.Decimal); Assert.True(columnInfo.Capacity == 10); }
private void FillColumnCache(IDbConnection connection) { var columns = new List <TableColumnInfoPair>(); var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = GetTables().Select(t => string.Format("SHOW COLUMNS FROM `{0}`;", t.ActualName)).Aggregate((result, next) => result += next); using (var reader = command.ExecuteReader()) { var i = 0; do { while (reader.Read()) { columns.Add(new TableColumnInfoPair( _cachedTables.ElementAt(i), MysqlColumnInfo.CreateColumnInfo( reader[0].ToString(), reader[5].ToString(), reader[1].ToString(), reader[3].ToString()) ) ); } i++; } while ((reader.NextResult())); } _cachedColumns = columns; }
public IEnumerable <Parameter> GetParameters(Procedure storedProcedure) { var list = new List <Parameter>(); using (var connection = _connectionProvider.CreateConnection()) { connection.Open(); var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = string.Format("SELECT * FROM information_schema.parameters WHERE SPECIFIC_NAME = '{0}';", storedProcedure.Name); using (var reader = command.ExecuteReader()) { while (reader.Read()) { list.Add(new Parameter ( reader["PARAMETER_NAME"].ToString(), SqlTypeResolver.GetClrType(reader["DATA_TYPE"].ToString()), GetParameterDirection(reader["PARAMETER_MODE"].ToString()), MysqlColumnInfo.GetDbType(reader["DATA_TYPE"].ToString()), Convert.IsDBNull(reader["CHARACTER_MAXIMUM_LENGTH"]) ? -1 : Convert.ToInt32(reader["CHARACTER_MAXIMUM_LENGTH"]) )); } } connection.Close(); return(list); } }
private void FillColumnCache(IDbConnection connection) { var columns = new List <TableColumnInfoPair>(); var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = string.Format("SELECT TABLE_NAME, COLUMN_NAME, EXTRA, COLUMN_TYPE, COLUMN_KEY FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{0}' ORDER BY TABLE_NAME;", _cachedSchema); using (var reader = command.ExecuteReader()) { while (reader.Read()) { columns.Add(new TableColumnInfoPair( new Table(reader[0].ToString(), null, TableType.Table), MysqlColumnInfo.CreateColumnInfo(reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString()) ) ); } } _cachedColumns = columns; }
public TableColumnInfoPair(Table table, MysqlColumnInfo columnInfo) { Table = table; ColumnInfo = columnInfo; }
public void SholdNotBePrimaryKeyWhenNotPassedPriAsLastParameter() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("", "", "int(11)", ""); Assert.False(columnInfo.IsPrimaryKey, "Column should not have been designated as primaryKey"); }
public void SholdBePrimaryKeyWhenPassedPriAsLastParameter() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("", "", "int(11)", "PRI"); Assert.True(columnInfo.IsPrimaryKey, "Column should have been designated as primaryKey"); }
public void CapacityShouldBeZeroWhenParsingFromTypeinfoWithoutCapacity() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("", "", "timestamp", ""); Assert.AreEqual(0, columnInfo.Capacity, "Capacity is not zero"); }
public void ParsesTypeFromTypeinfoWithoutCapacity() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("", "", "timestamp", ""); Assert.AreEqual(DbType.DateTime, columnInfo.DbType, "Dbtype is not correct"); }
public void ParsesCapacityFromTypeinfoWithCapacity() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("", "", "varchar(255)", ""); Assert.AreEqual(255, columnInfo.Capacity, "Capacity is not correct"); }
public void ParsesTypeFromTypeinfoWithCapacity() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("", "", "varchar(255)", ""); Assert.AreEqual(DbType.String, columnInfo.DbType, "Dbtype is not correct"); }
public void DecimalColumnWithoutCapacityParsedToDecimal() { var columnInfo = MysqlColumnInfo.CreateColumnInfo("Price", "Price", "decimal", "price"); Assert.True(columnInfo.DbType == DbType.Decimal); }