本文整理汇总了C#中Oracle.DataAccess.Client.OracleConnection.GetSchema方法的典型用法代码示例。如果您正苦于以下问题:C# OracleConnection.GetSchema方法的具体用法?C# OracleConnection.GetSchema怎么用?C# OracleConnection.GetSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oracle.DataAccess.Client.OracleConnection
的用法示例。
在下文中一共展示了OracleConnection.GetSchema方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSchema
/// <summary>
/// 返回指定名称的架构信息
/// </summary>
/// <param name="collectionName">集合名称</param>
/// <returns>DataTable</returns>
public static DataTable GetSchema(string collectionName)
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
DataTable dt = new DataTable();
try
{
dt.Clear();
connection.Open();
dt = connection.GetSchema(collectionName);
}
catch
{
dt = null;
}
return dt;
}
}
示例2: Connection
public DbConnection Connection(DatabaseType dbT, string cs)
{
DbConnection c = null;
switch (dbT)
{
case DatabaseType.SQLite: c = new SQLiteConnection(cs); break;
case DatabaseType.Access: c = new OleDbConnection(cs); break;
case DatabaseType.Oracle: c = new OracleConnection(cs); break;
default: break;
}
try
{
c.Open();
c.GetSchema("Tables");
}
catch
{
return null;
}
return c;
}
示例3: GetSchema_OracleDA
private DataTable GetSchema_OracleDA()
{
OracleConnection conn;
string connetionString = GetConnectionString_OracleDA();
conn = new OracleConnection(connetionString);
try
{
conn.Open();
DataTable schemaTable = conn.GetSchema();
return schemaTable;
}
catch (OracleException ex)
{
MessageBox.Show("Exception in GetSchema_OracleDA - " + ex.Message);
}
finally
{
conn.Close();
}
return null;
}
示例4: GetSchema
/// <summary>
/// 获取架构信息
/// </summary>
/// <param name="connectionString"></param>
/// <param name="collectionName"></param>
/// <param name="restrictionValues"></param>
/// <returns></returns>
public static DataTable GetSchema(string connectionString, string collectionName, string[] restrictionValues)
{
OracleConnection connection = new OracleConnection(connectionString);
DataTable schema = new DataTable();
try
{
connection.Open();
if (!string.IsNullOrEmpty(collectionName))
{
if (restrictionValues != null && restrictionValues != null && restrictionValues.Length > 0)
{
schema = connection.GetSchema(collectionName, restrictionValues);
}
else
{
schema = connection.GetSchema(collectionName);
}
}
else
{
schema = connection.GetSchema();
}
}
catch
{
schema = null;
}
finally
{
connection.Close();
}
return schema;
}
示例5: OracleGetShcema
private void OracleGetShcema()
{
try
{
using (var conn = new OracleConnection(txtOrclConn.Text))
{
conn.Open();
string[] restriction = new string[] { txtOrclOwner.Text };
DataTable schema;
if (txtOrclSchemaName.Text.ToLower() == "datatypes")
{
schema = conn.GetSchema(txtOrclSchemaName.Text);
}
else if (txtOrclSchemaName.Text.Length > 0)
{
schema = conn.GetSchema(txtOrclSchemaName.Text, restriction);
}
else
schema = conn.GetSchema();
grdGrid.DataSource = schema;
grdColumns.DataSource = GetColumns(schema.Columns);
}
}
catch
{
throw;
}
}
示例6: Main
public static void Main(string[] args)
{
var nameSpace = args[0];
var match = new Regex("^(?<user>[a-zA-Z0-9]+)/(?<password>[a-zA-Z0-9]+)@(?<tnsName>[a-zA-Z0-9]+)").Match(args[1]);
var user = match.Groups["user"].Value;
var password = match.Groups["password"].Value;
var tnsName = match.Groups["tnsName"].Value;
var connectionString = String.Format(
"User Id={0};Password={1};Data Source={2}",
user,
password,
tnsName);
using (var conn = new OracleConnection(connectionString))
{
try
{
conn.Open();
}
catch (OracleException ex)
{
Console.WriteLine(ex.Message);
return;
}
var typeDictionary = conn.GetSchema("DataTypes").AsDynamic()
.ToDictionary(x =>
x.TypeName,
x => (Type)Type.GetType(x.DataType));
Func<string, bool, decimal, decimal, string> getTypeName = (dataType, isNullable, precision, scale) =>
{
var type = typeDictionary[dataType];
var typeName = type.Name;
if (precision > 0 && scale == 0)
{
// NUMBER型が無条件にDecimalになるので、小数桁数が0なら整数型として扱う
if (precision < 10)
{
typeName = "Int32";
}
else
{
typeName = "Int64";
}
}
return (isNullable && type.IsValueType)
? typeName + "?" // 値型かつnull許可の時
: typeName;
};
var columnGroups = conn.GetSchema("Columns").AsDynamic()
.Where(x => x.OWNER == user)
.GroupBy(x => x.TABLE_NAME) // 全てのカラムが平らに列挙されてくるのでテーブル名でグルーピング
.Select(g => new
{
ClassName = g.Key, // クラス名はテーブル名(= グルーピングのキー)
Properties = g
.OrderBy(x => x.ID) // どんな順序で来るか不明なので、カラム定義順にきちんと並び替え
.Select(x => new
{
Name = x.COLUMN_NAME,
Type = getTypeName(
x.DATATYPE,
x.NULLABLE == "Y",
x.PRECISION ?? 0m,
x.SCALE ?? 0m)
})
.ToArray()
});
foreach (var item in columnGroups)
{
var tt = new TableGeneratorTemplate(nameSpace, item.ClassName, item.Properties);
var text = tt.TransformText();
File.WriteAllText(item.ClassName + ".cs", text, Encoding.UTF8);
}
}
}