public int GetColumnType(short index, ref short type, ref short subType) { this.CheckPosition(); this.CheckIndex(index); type = (short)BdpTypeHelper.GetBdpType(fields[index].DbDataType); subType = (short)BdpTypeHelper.GetBdpSubType(fields[index].DbDataType); return(0); }
public DataTable GetProcedureParams(string spName, string paramName) { StringBuilder sql = new StringBuilder(); StringBuilder where = new StringBuilder(); FbCommand select = new FbCommand(this.connection); ISQLCursor cursor = null; short resultCols = 0; DataTable schema = BdpMetaDataHelper.GetProcedureParams(); sql.Append( @"SELECT " + "pp.rdb$procedure_name AS ProcName, " + "pp.rdb$parameter_name AS ParamName, " + "pp.rdb$parameter_type AS ParamType, " + "pp.rdb$parameter_number AS ParamPosition, " + "fld.rdb$field_type AS ParamDataType, " + "fld.rdb$field_sub_type AS ParamSubType, " + "fld.rdb$field_length AS ParamSize, " + "fld.rdb$field_precision AS ParamPrecision, " + "fld.rdb$field_scale AS ParamScale " + "FROM " + "rdb$procedure_parameters pp " + "left join rdb$fields fld ON pp.rdb$field_source = fld.rdb$field_name " + "left join rdb$character_sets cs ON cs.rdb$character_set_id = fld.rdb$character_set_id " + "left join rdb$collations coll ON (coll.rdb$collation_id = fld.rdb$collation_id AND coll.rdb$character_set_id = fld.rdb$character_set_id) "); if (spName != null && spName.Length > 0) { where.AppendFormat("pp.rdb$procedure_name = '{0}'", spName); } if (paramName != null && paramName.Length > 0) { if (where.Length > 0) { where.Append(" AND "); } where.AppendFormat("pp.rdb$parameter_name = '{0}'", paramName); } if (where.Length > 0) { sql.AppendFormat(" WHERE {0} ", where.ToString()); } // Prepare and execute the command select.Prepare(sql.ToString(), 0); select.Execute(out cursor, ref resultCols); int recno = 0; while (cursor.Next() != -1) { DataRow row = schema.NewRow(); int blrType = 0; int subType = 0; int length = 0; int precision = 0; int scale = 0; int direction = 0; if (((FbCursor)cursor).GetValue(4) != null && ((FbCursor)cursor).GetValue(4) != DBNull.Value) { blrType = Convert.ToInt32(((FbCursor)cursor).GetValue(4)); } if (((FbCursor)cursor).GetValue(5) != null && ((FbCursor)cursor).GetValue(5) != DBNull.Value) { subType = Convert.ToInt32(((FbCursor)cursor).GetValue(5)); } if (((FbCursor)cursor).GetValue(6) != null && ((FbCursor)cursor).GetValue(6) != DBNull.Value) { length = Convert.ToInt32(((FbCursor)cursor).GetValue(6)); } if (((FbCursor)cursor).GetValue(7) != null && ((FbCursor)cursor).GetValue(7) != DBNull.Value) { precision = Convert.ToInt32(((FbCursor)cursor).GetValue(7)); } if (((FbCursor)cursor).GetValue(8) != null && ((FbCursor)cursor).GetValue(8) != DBNull.Value) { scale = Convert.ToInt32(((FbCursor)cursor).GetValue(8)); } if (((FbCursor)cursor).GetValue(2) != null && ((FbCursor)cursor).GetValue(2) != DBNull.Value) { direction = Convert.ToInt16(((FbCursor)cursor).GetValue(2)); } DbDataType paramDbType = TypeHelper.GetDbDataType(blrType, subType, scale); row["Recno"] = recno++; row["CatalogName"] = null; row["SchemaName"] = null; row["ProcName"] = ((FbCursor)cursor).GetValue(0).ToString().Trim(); row["ParamName"] = ((FbCursor)cursor).GetValue(1).ToString().Trim(); if (direction == 0) { row["ParamType"] = ParameterDirection.Input; } else if (direction == 1) { row["ParamType"] = ParameterDirection.Output; } row["ParamPosition"] = Convert.ToInt16(((FbCursor)cursor).GetValue(3)); row["ParamDataType"] = BdpTypeHelper.GetBdpType(paramDbType); row["ParamSubType"] = BdpTypeHelper.GetBdpSubType(paramDbType); row["ParamTypeName"] = TypeHelper.GetDataTypeName(paramDbType); row["ParamLength"] = length; row["ParamPrecision"] = precision; row["ParamScale"] = Convert.ToInt16(scale); row["ParamNullable"] = true; schema.Rows.Add(row); } cursor.Release(); select.Release(); return(schema); }
// Added by RPH to support Delphi 2006 public DataTable GetSchemaTable(IDataReader reader, IDbCommand command, ISQLCursor cursor) { DataTable schema = BdpMetaDataHelper.GetSchemaTable(); /* Prepare the command that is requested for obtain * schema information */ FbCommand c = (FbCommand)this.connection.GetSQLCommand(); c.Prepare(command.CommandText, (short)command.Parameters.Count); Descriptor fields = c.GetFieldsDescriptor(); /* Prepare the command used to obtain schema information like * Primary and Unique Key information ... */ short numCols = 0; // RPH - currentTable is no longer used. //string currentTable = ""; FbCommand sc = (FbCommand)this.connection.GetSQLCommand(); sc.Prepare(this.GetSchemaCommandText(), 2); // Fill schema information for (int i = 0; i < fields.Count; i++) { bool isKeyColumn = false; bool isUnique = false; bool isReadOnly = true; // Get schema information sc.SetParameter(0, 0, ParameterDirection.Input, BdpType.String, BdpType.stFixed, 0, 0, 31, fields[i].Relation, true); sc.SetParameter(1, 0, ParameterDirection.Input, BdpType.String, BdpType.stFixed, 0, 0, 31, fields[i].Name, true); sc.Execute(out cursor, ref numCols); if (cursor.Next() == 0) { if (((FbCursor)cursor).GetValue(0) != System.DBNull.Value || ((FbCursor)cursor).GetValue(1) != System.DBNull.Value) { isReadOnly = true; } else { isReadOnly = false; } if (Convert.ToInt32(((FbCursor)cursor).GetValue(2)) > 0) { isKeyColumn = true; } if (Convert.ToInt32(((FbCursor)cursor).GetValue(3)) > 0) { isUnique = true; } } // Add column schema information DataRow row = schema.NewRow(); row["ColumnName"] = fields[i].Alias.Length > 0 ? fields[i].Alias : fields[i].Name; row["ColumnOrdinal"] = i; row["ColumnSize"] = fields[i].GetSize(); if (fields[i].IsNumeric()) { row["NumericPrecision"] = fields[i].GetSize(); row["NumericScale"] = fields[i].NumericScale * (-1); } row["DataType"] = fields[i].GetSystemType(); row["ProviderType"] = BdpTypeHelper.GetBdpType(fields[i].DbDataType); row["IsLong"] = fields[i].IsLong(); row["AllowDBNull"] = fields[i].AllowDBNull(); row["NumericPrecision"] = 0; row["IsAutoIncrement"] = false; row["IsRowVersion"] = false; row["IsReadOnly"] = isReadOnly; row["IsUnique"] = isUnique; row["IsKeyColumn"] = isKeyColumn; row["BaseSchemaName"] = DBNull.Value; row["BaseCatalogName"] = DBNull.Value; row["BaseTableName"] = fields[i].Relation; row["BaseColumnName"] = fields[i].Name; row["ProviderSubType"] = BdpTypeHelper.GetBdpSubType(fields[i].DbDataType);; // RPH - Modified to support multiple tables in the command. CheckColumns // in FbResolver will fail when using multiple tables in a command. schema.Rows.Add(row); sc.Close(); } // Free resources cursor.Release(); c.Release(); sc.Release(); return(schema); }