mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
-
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
@@ -80,7 +82,31 @@ namespace SqlSugar
|
||||
return method.ReflectedType;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdoCore
|
||||
{
|
||||
public static List<DbColumnInfo> GetColumnInfosByTableName(string tableName, DbDataReader dataReader)
|
||||
{
|
||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||
var schemaTable = dataReader.GetSchemaTable();
|
||||
foreach (DataRow row in schemaTable.Rows)
|
||||
{
|
||||
DbColumnInfo column = new DbColumnInfo()
|
||||
{
|
||||
TableName = tableName,
|
||||
DataType = row["DataTypeName"].ToString().Trim(),
|
||||
IsNullable = (bool)row["AllowDBNull"],
|
||||
IsIdentity = (bool)row["IsAutoIncrement"],
|
||||
ColumnDescription = null,
|
||||
DbColumnName = row["ColumnName"].ToString(),
|
||||
DefaultValue = row["defaultValue"].ToString(),
|
||||
IsPrimarykey = (bool)row["IsKey"],
|
||||
Length = Convert.ToInt32(row["ColumnSize"])
|
||||
};
|
||||
result.Add(column);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public static class ReflectionCore
|
||||
{
|
||||
public static Assembly Load(string name)
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SQLite;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -172,30 +174,14 @@ namespace SqlSugar
|
||||
|
||||
}, (cm, key) =>
|
||||
{
|
||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||
using (var dataReader = this.Context.Ado.GetDataReader("select * from " + tableName + " limit 0,1"))
|
||||
string sql = "select * from " + tableName + " limit 0,1";
|
||||
using (DbDataReader reader = new SQLiteCommand(sql).ExecuteReader(System.Data.CommandBehavior.SchemaOnly))
|
||||
{
|
||||
var schemaTable = dataReader.GetSchemaTable();
|
||||
foreach (DataRow row in schemaTable.Rows)
|
||||
{
|
||||
DbColumnInfo column = new DbColumnInfo()
|
||||
{
|
||||
TableName = tableName,
|
||||
DataType = row["DataTypeName"].ToString().Trim(),
|
||||
IsNullable = (bool)row["AllowDBNull"],
|
||||
IsIdentity = (bool)row["IsAutoIncrement"],
|
||||
ColumnDescription = null,
|
||||
DbColumnName = row["ColumnName"].ToString(),
|
||||
DefaultValue = row["defaultValue"].ToString(),
|
||||
IsPrimarykey = (bool)row["IsKey"],
|
||||
Length = Convert.ToInt32(row["ColumnSize"])
|
||||
};
|
||||
result.Add(column);
|
||||
}
|
||||
return AdoCore.GetColumnInfosByTableName(tableName, reader);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns)
|
||||
{
|
||||
if (columns.IsValuable())
|
||||
|
Reference in New Issue
Block a user