diff --git a/DBChm/DBForm.cs b/DBChm/DBForm.cs
index 2a5eaa98e894188e17e9d17cceecb7845469772a..d371f9eccf87b4289e1c60fb35b2fef8bb6f5c9e 100644
--- a/DBChm/DBForm.cs
+++ b/DBChm/DBForm.cs
@@ -1,62 +1,62 @@
-using ComponentFactory.Krypton.Toolkit;
-using MJTop.Data;
-using System;
+using ComponentFactory.Krypton.Toolkit;
+using MJTop.Data;
+using System;
using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Windows.Forms;
-
-namespace DBCHM
-{
- public partial class DBForm : KryptonForm
- {
- private DBForm()
- : this(OPType.新建)
- {
-
- }
-
- ///
- /// 当前操作类型
- ///
- public OPType OpType { get; private set; }
-
+using System.Collections.Specialized;
+using System.Windows.Forms;
+
+namespace DBCHM
+{
+ public partial class DBForm : KryptonForm
+ {
+ private DBForm()
+ : this(OPType.新建)
+ {
+
+ }
+
+ ///
+ /// 当前操作类型
+ ///
+ public OPType OpType { get; private set; }
+
public int Id { get; private set; }
- public DBForm(OPType opType, int? id = null)
- {
- InitializeComponent();
-
- this.OpType = opType;
-
- if ((this.OpType == OPType.编辑 || this.OpType == OPType.克隆) && !id.HasValue)
- {
- throw new ArgumentNullException(this.OpType + "操作必须传递要操作的Id!");
- }
- else
- {
- if (id.HasValue)
- {
- foreach (var item in FormUtils.DictDBType)
- {
- cboDBType.Items.Add(item.Value.ToString());
- }
-
- this.Id = id.Value;
- DBCHMConfig config = ConfigUtils.Get(id.Value);
- TxtConnectName.Text = config.Name;
- cboDBType.Text = config.DBType;
- TxtHost.Text = config.Server;
- TxtPort.Text = config.Port?.ToString();
- TxtUName.Text = config.Uid;
- TxtPwd.Text = config.Pwd;
+ public DBForm(OPType opType, int? id = null)
+ {
+ InitializeComponent();
+
+ this.OpType = opType;
+
+ if ((this.OpType == OPType.编辑 || this.OpType == OPType.克隆) && !id.HasValue)
+ {
+ throw new ArgumentNullException(this.OpType + "操作必须传递要操作的Id!");
+ }
+ else
+ {
+ if (id.HasValue)
+ {
+ foreach (var item in FormUtils.DictDBType)
+ {
+ cboDBType.Items.Add(item.Value.ToString());
+ }
+
+ this.Id = id.Value;
+ DBCHMConfig config = ConfigUtils.Get(id.Value);
+ TxtConnectName.Text = config.Name;
+ cboDBType.Text = config.DBType;
+ TxtHost.Text = config.Server;
+ TxtPort.Text = config.Port?.ToString();
+ TxtUName.Text = config.Uid;
+ TxtPwd.Text = config.Pwd;
cboDBName.Text = config.DBName;
txtConnTimeOut.Text = config.ConnTimeOut?.ToString();
- if (this.OpType == OPType.克隆)
- {
- TxtConnectName.Text += "_Clone";
- }
-
+ if (this.OpType == OPType.克隆)
+ {
+ TxtConnectName.Text += "_Clone";
+ }
+
if (config.DBType == DBType.SQLite.ToString())
{
btnSelectFile.Visible = true;
@@ -67,56 +67,56 @@ namespace DBCHM
//暂不支持 加密的 Sqlite数据库
TxtPwd.Enabled = false;
- }
-
- //编辑时,确定后刷新连接列表
- BtnOk.DialogResult = DialogResult.OK;
+ }
+
+ //编辑时,确定后刷新连接列表
+ BtnOk.DialogResult = DialogResult.OK;
}
else
{
btnSelectFile.Visible = false;
- }
-
+ }
+
if (string.IsNullOrWhiteSpace(txtConnTimeOut.Text))
{
txtConnTimeOut.Text = "30";
- }
- }
-
- //为KeyDown能应用到所有控件上 注册 KeyDown 事件
- foreach (Control control in this.Controls)
- {
- control.KeyDown += control_KeyDown;
- }
- lblMsg.Text = string.Empty;
- }
-
- void control_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Escape)
- {
- this.Close();
- }
- }
-
- private void DBFrom_Load(object sender, EventArgs e)
- {
- if (OpType == OPType.新建)
- {
- foreach (var item in FormUtils.DictDBType)
- {
- cboDBType.Items.Add(item.Value.ToString());
- }
- cboDBType.SelectedIndex = 0;
- string port;
- if (FormUtils.DictPort.TryGetValue(cboDBType.Text, out port))
- {
- TxtPort.Text = port;
- }
+ }
+ }
+
+ //为KeyDown能应用到所有控件上 注册 KeyDown 事件
+ foreach (Control control in this.Controls)
+ {
+ control.KeyDown += control_KeyDown;
+ }
+ lblMsg.Text = string.Empty;
+ }
+
+ void control_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Escape)
+ {
+ this.Close();
+ }
+ }
+
+ private void DBFrom_Load(object sender, EventArgs e)
+ {
+ if (OpType == OPType.新建)
+ {
+ foreach (var item in FormUtils.DictDBType)
+ {
+ cboDBType.Items.Add(item.Value.ToString());
+ }
+ cboDBType.SelectedIndex = 0;
+ string port;
+ if (FormUtils.DictPort.TryGetValue(cboDBType.Text, out port))
+ {
+ TxtPort.Text = port;
+ }
TxtHost.Text = "127.0.0.1";
// TODO 设置默认用户名等
- SetUserNameByDbType();
- }
+ SetUserNameByDbType();
+ }
}
private void BtnSelectFile_Click(object sender, EventArgs e)
{
@@ -126,33 +126,33 @@ namespace DBCHM
{
cboDBName.Text = fileDia.FileName;
}
- }
-
- public void SetMsg(string msg, bool isSuccess = false)
- {
- lblMsg.Text = msg;
- lblMsg.ForeColor = isSuccess ? System.Drawing.Color.Green : System.Drawing.Color.Red;
- }
-
- private void BtnTestConnect_Click(object sender, EventArgs e)
- {
+ }
+
+ public void SetMsg(string msg, bool isSuccess = false)
+ {
+ lblMsg.Text = msg;
+ lblMsg.ForeColor = isSuccess ? System.Drawing.Color.Green : System.Drawing.Color.Red;
+ }
+
+ private void BtnTestConnect_Click(object sender, EventArgs e)
+ {
DBType type = (DBType)Enum.Parse(typeof(DBType), cboDBType.Text);
- try
- {
- if ((type == DBType.Oracle || type == DBType.OracleDDTek) && string.IsNullOrWhiteSpace(cboDBName.Text))
- {
- throw new Exception("Oracle没有提供数据库名称查询支持,请输入服务名!");
+ try
+ {
+ if ((type == DBType.Oracle || type == DBType.OracleDDTek) && string.IsNullOrWhiteSpace(cboDBName.Text))
+ {
+ throw new Exception("Oracle没有提供数据库名称查询支持,请输入服务名!");
}
- if ((type == DBType.DM) && string.IsNullOrWhiteSpace(cboDBName.Text))
- {
- throw new Exception("达梦DM没有提供数据库名称查询支持,请输入服务名!");
- }
- var connString = InitConnectionStr(type);
-
- List dbNames = null;
-
- DBMgr.TryConnect(type, connString, out dbNames);
-
+ // if ((type == DBType.DM) && string.IsNullOrWhiteSpace(cboDBName.Text))
+ // {
+ // throw new Exception("达梦DM没有提供数据库名称查询支持,请输入服务名!");
+ // }
+ var connString = InitConnectionStr(type);
+
+ List dbNames = null;
+
+ DBMgr.TryConnect(type, connString, out dbNames);
+
if (dbNames != null && dbNames.Count > 0)
{
cboDBName.Items.Clear();
@@ -160,75 +160,75 @@ namespace DBCHM
{
cboDBName.Items.Add(dbName);
}
- }
-
- this.Text = "连接服务器成功!";
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
-
- private void BtnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- private void BtnOk_Click(object sender, EventArgs e)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(TxtConnectName.Text))
+ }
+
+ this.Text = "连接服务器成功!";
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+ }
+
+ private void BtnCancel_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+ private void BtnOk_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(TxtConnectName.Text))
{
MessageBox.Show("请输入连接名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
- if (string.IsNullOrWhiteSpace(cboDBName.Text))
+ return;
+ }
+
+ if (string.IsNullOrWhiteSpace(cboDBName.Text))
{
MessageBox.Show("请输入数据库名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
-
+ return;
+ }
+
DBType type = (DBType)Enum.Parse(typeof(DBType), cboDBType.Text);
string connString = InitConnectionStr(type);
- NameValueCollection nvc = new NameValueCollection();
- if (OpType == OPType.新建 || OpType == OPType.克隆)
- {
- nvc.Add("Name", TxtConnectName.Text.Trim());
- nvc.Add("DBType", cboDBType.Text.Trim());
-
- nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
- nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
- nvc.Add("DBName", cboDBName.Text.Trim());
- nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
- nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
- nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "30");
+ NameValueCollection nvc = new NameValueCollection();
+ if (OpType == OPType.新建 || OpType == OPType.克隆)
+ {
+ nvc.Add("Name", TxtConnectName.Text.Trim());
+ nvc.Add("DBType", cboDBType.Text.Trim());
+
+ nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
+ nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
+ nvc.Add("DBName", cboDBName.Text.Trim());
+ nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
+ nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
+ nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "30");
+ nvc.Add("ConnString", connString);
+ nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
+
+ ConfigUtils.Save(nvc);
+
+ }
+ else if (OpType == OPType.编辑)
+ {
+ nvc.Add("Id", Id.ToString());
+ nvc.Add("Name", TxtConnectName.Text.Trim());
+ nvc.Add("DBType", cboDBType.Text.Trim());
+
+ nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
+ nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
+ nvc.Add("DBName", cboDBName.Text.Trim());
+ nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
+ nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
+ nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "30");
nvc.Add("ConnString", connString);
- nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
-
- ConfigUtils.Save(nvc);
-
- }
- else if (OpType == OPType.编辑)
- {
- nvc.Add("Id", Id.ToString());
- nvc.Add("Name", TxtConnectName.Text.Trim());
- nvc.Add("DBType", cboDBType.Text.Trim());
-
- nvc.Add("Server", TxtHost.Enabled ? TxtHost.Text.Trim() : string.Empty);
- nvc.Add("Port", TxtPort.Enabled ? TxtPort.Text : string.Empty);
- nvc.Add("DBName", cboDBName.Text.Trim());
- nvc.Add("Uid", TxtUName.Enabled ? TxtUName.Text.Trim() : string.Empty);
- nvc.Add("Pwd", TxtPwd.Enabled ? TxtPwd.Text : string.Empty);
- nvc.Add("ConnTimeOut", txtConnTimeOut.Enabled ? txtConnTimeOut.Text : "30");
- nvc.Add("ConnString", connString);
- nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- ConfigUtils.Save(nvc);
+ nvc.Add("Modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
+ ConfigUtils.Save(nvc);
}
@@ -243,28 +243,28 @@ namespace DBCHM
LogUtils.LogError("BtnOk_Click", Developer.SysDefault, ex, connString);
}
- }, null);
-
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
-
- private void cboDBType_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.Text = "连接数据库";
- string port;
- if (FormUtils.DictPort.TryGetValue(cboDBType.Text, out port))
- {
- TxtPort.Text = port;
+ }, null);
+
+ this.DialogResult = DialogResult.OK;
+ this.Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+ }
+
+ private void cboDBType_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ this.Text = "连接数据库";
+ string port;
+ if (FormUtils.DictPort.TryGetValue(cboDBType.Text, out port))
+ {
+ TxtPort.Text = port;
}
// TODO 设置默认用户名等
- SetUserNameByDbType();
+ SetUserNameByDbType();
}
///
@@ -277,14 +277,15 @@ namespace DBCHM
TxtHost.Enabled = true;
TxtPort.Enabled = true;
TxtUName.Enabled = true;
+ TxtPwd.Enabled = true;
sslLabel.Visible = false;
extraParam1.Visible = false;
mssqlServiceDesc.Visible = false;
cbUserIsSchema.Visible = false;
- labDBName.Text = "数据库";
- DBType dbtype = (DBType)Enum.Parse(typeof(DBType), cboDBType.Text.ToString());
+ labDBName.Text = "数据库";
+ DBType dbtype = (DBType)Enum.Parse(typeof(DBType), cboDBType.Text.ToString());
if (dbtype == DBType.SqlServer)
{
TxtUName.Text = "sa";
@@ -346,58 +347,58 @@ namespace DBCHM
}
}
- ///
- /// 端口验证 只能输入数字
- ///
- ///
- ///
- private void TxtPort_KeyPress(object sender, KeyPressEventArgs e)
- {
- e.Handled = true;
- if (e.KeyChar == 8 || e.KeyChar == 127)//退格删除,delete删除
- {
- e.Handled = false;
- }
- else
- {
- if (e.KeyChar >= '0' && e.KeyChar <= '9')//只能输入数字
- {
- int maxPort = 0;
- int.TryParse(TxtPort.Text + e.KeyChar.ToString(), out maxPort);
- if (maxPort > 0 && maxPort <= 65535)
- {
- e.Handled = false;
- }
- }
- }
-
+ ///
+ /// 端口验证 只能输入数字
+ ///
+ ///
+ ///
+ private void TxtPort_KeyPress(object sender, KeyPressEventArgs e)
+ {
+ e.Handled = true;
+ if (e.KeyChar == 8 || e.KeyChar == 127)//退格删除,delete删除
+ {
+ e.Handled = false;
+ }
+ else
+ {
+ if (e.KeyChar >= '0' && e.KeyChar <= '9')//只能输入数字
+ {
+ int maxPort = 0;
+ int.TryParse(TxtPort.Text + e.KeyChar.ToString(), out maxPort);
+ if (maxPort > 0 && maxPort <= 65535)
+ {
+ e.Handled = false;
+ }
+ }
+ }
+
+ }
+
+ private void txtConnectionOut_KeyPress(object sender, KeyPressEventArgs e)
+ {
+ e.Handled = true;
+ if (e.KeyChar == 8 || e.KeyChar == 127)//退格删除,delete删除
+ {
+ e.Handled = false;
+ }
+ else
+ {
+ if (e.KeyChar >= '0' && e.KeyChar <= '9')//只能输入数字
+ {
+ int timtOut = 0;
+ int.TryParse(TxtPort.Text + e.KeyChar.ToString(), out timtOut);
+ if (timtOut > -1)
+ {
+ e.Handled = false;
+ }
+ }
+ }
+
}
- private void txtConnectionOut_KeyPress(object sender, KeyPressEventArgs e)
- {
- e.Handled = true;
- if (e.KeyChar == 8 || e.KeyChar == 127)//退格删除,delete删除
- {
- e.Handled = false;
- }
- else
- {
- if (e.KeyChar >= '0' && e.KeyChar <= '9')//只能输入数字
- {
- int timtOut = 0;
- int.TryParse(TxtPort.Text + e.KeyChar.ToString(), out timtOut);
- if (timtOut > -1)
- {
- e.Handled = false;
- }
- }
- }
-
- }
-
- private void cboDBName_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.Text = "连接数据库";
+ private void cboDBName_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ this.Text = "连接数据库";
}
private string extraParam = ""; // 额外参数
@@ -529,5 +530,5 @@ namespace DBCHM
private const string DEFAULT_MSSQL_INSTANCE = "实例名(默认为空)";
- }
-}
+ }
+}
diff --git a/MJTop.Data/DBFactotry.cs b/MJTop.Data/DBFactotry.cs
index 3c2186a38b1d10289b199b3bfa17ba6f8fb31efb..de9acf83d2cdc85772370f9494fa79213297b59d 100644
--- a/MJTop.Data/DBFactotry.cs
+++ b/MJTop.Data/DBFactotry.cs
@@ -26,11 +26,11 @@ namespace MJTop.Data
case DBType.SqlServer:
return new SqlServerDB(dbType, SqlClientFactory.Instance, connectionString,cmdTimeOut);
case DBType.MySql:
- return new MySqlDB(dbType, MySqlClientFactory.Instance, connectionString, cmdTimeOut);
+ return new MySqlDB(dbType, MySqlClientFactory.Instance, connectionString, cmdTimeOut);
case DBType.DM:
- return new DmDB(dbType, Dm.DmClientFactory.Instance, connectionString, cmdTimeOut);
+ return new DmDB(dbType, Dm.DmClientFactory.Instance, connectionString, cmdTimeOut);
case DBType.Oscar:
- return new OscarDB(dbType, OscarFactory.Instance, connectionString, cmdTimeOut);
+ return new OscarDB(dbType, OscarFactory.Instance, connectionString, cmdTimeOut);
case DBType.Kingbase:
return new KingbaseDB(dbType, KdbndpFactory.Instance, connectionString, cmdTimeOut);
case DBType.Oracle:
@@ -67,13 +67,13 @@ namespace MJTop.Data
cmd = MySqlClientFactory.Instance.CreateCommand();
cmd.CommandText = "select schema_name from information_schema.SCHEMATA where schema_name not in ('information_schema','performance_schema','mysql','sys') order by schema_name asc";
cmd.Connection = conn;
- break;
+ break;
case DBType.DM:
conn = Dm.DmClientFactory.Instance.CreateConnection();
cmd = Dm.DmClientFactory.Instance.CreateCommand();
- //cmd.CommandText = "";
+ cmd.CommandText = "SELECT NAME from SYSOBJECTS where TYPE$='SCH' and PID=UID()";
cmd.Connection = conn;
- break;
+ break;
case DBType.Oscar:
conn = OscarFactory.Instance.CreateConnection();
cmd = OscarFactory.Instance.CreateCommand();
@@ -130,6 +130,9 @@ namespace MJTop.Data
{
dbNames.Add(oraConn.ServiceName);
}
+ else if (conn is Dm.DmConnection)
+ {
+ }
else
{
dbNames.Add(conn.Database);
diff --git a/MJTop.Data/DatabaseInfo/DmDBInfo.cs b/MJTop.Data/DatabaseInfo/DmDBInfo.cs
index 17dffafa28407bbf5288cd3999cff5b5e8412ca4..96c0a39eb82a7d38d15f3019694faa50d9d3131e 100644
--- a/MJTop.Data/DatabaseInfo/DmDBInfo.cs
+++ b/MJTop.Data/DatabaseInfo/DmDBInfo.cs
@@ -59,6 +59,21 @@ namespace MJTop.Data.DatabaseInfo
}
}
}
+
+ public string Schema
+ {
+ get
+ {
+ if (Db.ConnectionStringBuilder is Dm.DmConnectionStringBuilder)
+ {
+ return (Db.ConnectionStringBuilder as Dm.DmConnectionStringBuilder).Schema?.ToUpper();
+ }
+ else
+ {
+ return (Db.ConnectionStringBuilder as Dm.DmConnectionStringBuilder).Schema?.ToUpper();
+ }
+ }
+ }
public string Version
{
@@ -141,17 +156,17 @@ namespace MJTop.Data.DatabaseInfo
this.TableColumnInfoDict = new IgCaseDictionary>(KeyCase.Upper);
this.TableColumnComments = new IgCaseDictionary(KeyCase.Upper);
- string sequence_Sql = string.Format("SELECT SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '{0}' ORDER BY SEQUENCE_NAME", User);
+ string sequence_Sql = string.Format("SELECT SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '{0}' ORDER BY SEQUENCE_NAME", Schema);
- string strSql = string.Format("SELECT TC.TABLE_NAME as Name, TC.COMMENTS as Value FROM all_tab_comments TC WHERE TC.OWNER = '{0}' ORDER BY TC.TABLE_NAME ASC", User);
+ string strSql = string.Format("SELECT TC.TABLE_NAME as Name, TC.COMMENTS as Value FROM all_tab_comments TC WHERE TC.OWNER = '{0}' AND TC.TABLE_TYPE = 'TABLE' ORDER BY TC.TABLE_NAME ASC", Schema);
- string viewSql = string.Format("select view_name,text from ALL_VIEWS WHERE OWNER = '{0}' order by view_name asc", User);
+ string viewSql = string.Format("select view_name,text from ALL_VIEWS WHERE OWNER = '{0}' order by view_name asc", Schema);
//Oracle 11g 推出 LISTAGG 函数,有可能会报:ora-01489 字符串连接的结果过长
string procSql = string.Format("select * from (SELECT name,LISTAGG(text,' ') WITHIN group (order by line asc) text FROM all_source where OWNER = '{0}' group by name ) order by name asc", User);
//https://blog.csdn.net/rczrj/article/details/74977010
- procSql = string.Format("select * from (SELECT name,xmlagg(xmlparse(content text||' ' wellformed) order by line asc).getclobval() text FROM all_source where OWNER = '{0}' group by name ) order by name asc", User);
+ procSql = string.Format("select * from (SELECT name,xmlagg(xmlparse(content text||' ' wellformed) order by line asc).getclobval() text FROM all_source where OWNER = '{0}' group by name ) order by name asc", Schema);
try
{
@@ -191,26 +206,27 @@ namespace MJTop.Data.DatabaseInfo
/** 该语句,包含某列是否自增列,查询慢 **/
strSql = @"select a.COLUMN_ID As Colorder,a.COLUMN_NAME As ColumnName,a.DATA_TYPE As TypeName,b.comments As DeText,(Case When a.DATA_TYPE='NUMBER' Then a.DATA_PRECISION When a.DATA_TYPE='NVARCHAR2' Then a.DATA_LENGTH/2 Else a.DATA_LENGTH End )As Length,a.DATA_SCALE As Scale,
- (Case When (select Count(1) from all_cons_columns aa, all_constraints bb where aa.OWNER = '{0}' and bb.OWNER = '{0}' and aa.constraint_name = bb.constraint_name and bb.constraint_type = 'P' and aa.table_name = '{1}' And aa.column_name=a.COLUMN_NAME)>0 Then 1 Else 0 End
+ (Case When (select Count(1) from all_cons_columns aa, all_constraints bb where aa.OWNER = '{2}' and bb.OWNER = '{2}' and aa.constraint_name = bb.constraint_name and bb.constraint_type = 'P' and aa.table_name = '{1}' And aa.column_name=a.COLUMN_NAME)>0 Then 1 Else 0 End
) As IsPK,(
case when (select count(1) from all_triggers tri INNER JOIN all_source src on tri.trigger_Name=src.Name
- where tri.OWNER = '{0}' and src.OWNER = '{0}' and (triggering_Event='INSERT' and table_name='{1}')
+ where tri.OWNER = '{2}' and src.OWNER = '{2}' and (triggering_Event='INSERT' and table_name='{1}')
and regexp_like(text,concat(concat('into\s*?:\s*?new\s*?\.\s*?',a.COLUMN_NAME),'\s+?'),'i'))>0
then 1 else 0 end
) As IsIdentity,
Case a.NULLABLE When 'Y' Then 1 Else 0 End As CanNull,
a.data_default As DefaultVal from all_tab_columns a Inner Join all_col_comments b On a.TABLE_NAME=b.table_name
- Where a.OWNER = '{0}' and b.OWNER = '{0}' and b.COLUMN_NAME= a.COLUMN_NAME and a.Table_Name='{1}' order by a.column_ID Asc";
+ Where a.OWNER = '{2}' and b.OWNER = '{2}' and b.COLUMN_NAME= a.COLUMN_NAME and a.Table_Name='{1}' order by a.column_ID Asc";
// 忽略 IsIdentity 查询
strSql = @"select a.COLUMN_ID As Colorder,a.COLUMN_NAME As ColumnName,a.DATA_TYPE As TypeName,b.comments As DeText,(Case When a.DATA_TYPE='NUMBER' Then a.DATA_PRECISION When a.DATA_TYPE='NVARCHAR2' Then a.DATA_LENGTH/2 Else a.DATA_LENGTH End )As Length,a.DATA_SCALE As Scale,
- (Case When (select Count(1) from all_cons_columns aa, all_constraints bb where aa.OWNER = '{0}' and bb.OWNER = '{0}' and aa.constraint_name = bb.constraint_name and bb.constraint_type = 'P' and aa.table_name = '{1}' And aa.column_name=a.COLUMN_NAME)>0 Then 1 Else 0 End
- ) As IsPK,0 As IsIdentity,
+ ifnull(pk.FLAG,0) As IsPK,ifnull(ident.FLAG,0) As IsIdentity,
Case a.NULLABLE When 'Y' Then 1 Else 0 End As CanNull,
a.data_default As DefaultVal from all_tab_columns a Inner Join all_col_comments b On a.TABLE_NAME=b.table_name
- Where a.OWNER = '{0}' and b.OWNER = '{0}' and b.COLUMN_NAME= a.COLUMN_NAME and a.Table_Name='{1}' order by a.column_ID Asc";
+ LEFT JOIN (select SO.NAME TABLE_NAME,SCO.NAME COLUMN_NAME,1 FLAG from SYSCOLUMNS SCO JOIN SYSOBJECTS SO ON SCO.ID=SO.id AND SO.SUBTYPE$='UTAB' WHERE SCO.INFO2&0x0001=1 and sf_get_schema_name_by_id(SO.SCHID)='{2}' and SO.NAME='{1}') ident on ident.COLUMN_NAME=a.COLUMN_NAME
+ LEFT JOIN (select aa.TABLE_NAME,aa.COLUMN_NAME,1 FLAG from all_cons_columns aa, all_constraints bb where aa.OWNER = '{2}' and bb.OWNER = '{2}' and aa.constraint_name = bb.constraint_name and bb.constraint_type = 'P' and aa.table_name = '{1}') pk on pk.COLUMN_NAME=a.COLUMN_NAME
+ Where a.OWNER = '{2}' and b.OWNER = '{0}' and b.SCHEMA_NAME='{2}' and b.COLUMN_NAME= a.COLUMN_NAME and a.Table_Name='{1}' order by a.column_ID Asc";
- strSql = string.Format(strSql, User, tableName);
+ strSql = string.Format(strSql, User, tableName, Schema);
try
{
@@ -227,10 +243,10 @@ namespace MJTop.Data.DatabaseInfo
this.DictColumnInfo.Add(strKey, colInfo);
//自增的列,需要查询序列名称
- if (colInfo.IsIdentity)
- {
- AddColSeq(tableName, colInfo.ColumnName);
- }
+ // if (colInfo.IsIdentity)
+ // {
+ // AddColSeq(tableName, colInfo.ColumnName);
+ // }
if (colInfo.IsPK)
{
@@ -302,7 +318,7 @@ namespace MJTop.Data.DatabaseInfo
public Dictionary GetTableStruct_Modify()
{
- string strSql = "select object_name as name ,last_ddl_time as modify_date from all_objects Where OWNER = '" + User + "' and object_Type='TABLE' Order By last_ddl_time Desc";
+ string strSql = "select object_name as name ,last_ddl_time as modify_date from all_objects Where OWNER = '" + Schema + "' and object_Type='TABLE' Order By last_ddl_time Desc";
return Db.ReadDictionary(strSql);
}
@@ -363,11 +379,12 @@ namespace MJTop.Data.DatabaseInfo
//tableName = (tableName ?? string.Empty);
+ tableName = "\"" + Schema + "\".\"" + tableName + "\"";
string upsert_sql = string.Empty;
comment = (comment ?? string.Empty).Replace("'", "");
try
{
- upsert_sql = "comment on table \"" + tableName + "\" is '" + comment + "'";
+ upsert_sql = "comment on table " + tableName + " is '" + comment + "'";
Db.ExecSql(upsert_sql);
TableComments[tableName] = comment;
@@ -390,12 +407,13 @@ namespace MJTop.Data.DatabaseInfo
//tableName = (tableName ?? string.Empty);
//columnName = (columnName ?? string.Empty);
-
+ tableName = "\"" + Schema + "\".\"" + tableName + "\"";
+
string upsert_sql = string.Empty;
comment = (comment ?? string.Empty).Replace("'", "");
try
{
- upsert_sql = "comment on column \"" + tableName + "\".\"" + columnName + "\" is '" + comment + "'";
+ upsert_sql = "comment on column " + tableName + ".\"" + columnName + "\" is '" + comment + "'";
Db.ExecSql(upsert_sql);
List lstColInfo = TableColumnInfoDict[tableName];