private int createTable_Oracle(BizProcess.Data.Model.DBExtract dbe) { System.Text.StringBuilder sql = new System.Text.StringBuilder(); sql.AppendFormat("CREATE TABLE {0}(", dbe.Name); //sql.AppendFormat("", dbe.Comment); var jsonData = LitJson.JsonMapper.ToObject(dbe.DesignJSON); BizProcess.Platform.DBConnection bdbConn = new BizProcess.Platform.DBConnection(); BizProcess.Data.Model.DBConnection conn = bdbConn.Get(dbe.DBConnID); using (System.Data.IDbConnection iconn = bdbConn.GetConnection(conn)) { try { if (iconn.State == ConnectionState.Closed) { iconn.Open(); } System.Data.DataTable schemaDt = bdbConn.GetTableSchema(iconn, jsonData["table"].ToString(), conn.Type); //primary key field string fieldname = jsonData["primarykey"].ToString(); System.Data.DataRow[] schemaDrs = schemaDt.Select(string.Format("f_name='{0}'", fieldname)); if (schemaDrs.Length == 0) { return(0); } sql.Append(getFieldString_Oracle(schemaDrs)); //fields var fields = LitJson.JsonMapper.ToObject(jsonData["fields"].ToJson()); foreach (LitJson.JsonData field in fields) { fieldname = field["field"].ToString(); schemaDrs = schemaDt.Select(string.Format("f_name='{0}'", fieldname)); if (schemaDrs.Length == 0) { return(0); } sql.Append(getFieldString_Oracle(schemaDrs)); } sql.AppendFormat("CONSTRAINT {0}_pk PRIMARY KEY ({1}))", dbe.Name, jsonData["primarykey"].ToString()); } catch (OracleException ex) { } } //create table into the system database return(dataDBExtract.ExecuteStatement(sql.ToString())); }
private int createTable_SqlServer(BizProcess.Data.Model.DBExtract dbe) { System.Text.StringBuilder sql = new System.Text.StringBuilder(); sql.AppendFormat("CREATE TABLE {0}(", dbe.Name); //sql.AppendFormat("", dbe.Comment); var jsonData = LitJson.JsonMapper.ToObject(dbe.DesignJSON); BizProcess.Platform.DBConnection bdbConn = new BizProcess.Platform.DBConnection(); BizProcess.Data.Model.DBConnection conn = bdbConn.Get(dbe.DBConnID); using (System.Data.IDbConnection iconn = bdbConn.GetConnection(conn)) { try { if (iconn.State == ConnectionState.Closed) { iconn.Open(); } System.Data.DataTable schemaDt = bdbConn.GetTableSchema(iconn, jsonData["table"].ToString(), conn.Type); //primary key field string fieldname = jsonData["primarykey"].ToString(); System.Data.DataRow[] schemaDrs = schemaDt.Select(string.Format("f_name='{0}'", fieldname)); if (schemaDrs.Length == 0) { return(0); } sql.Append(getFieldString_SqlServer(schemaDrs)); //fields var fields = LitJson.JsonMapper.ToObject(jsonData["fields"].ToJson()); foreach (LitJson.JsonData field in fields) { fieldname = field["field"].ToString(); schemaDrs = schemaDt.Select(string.Format("f_name='{0}'", fieldname)); if (schemaDrs.Length == 0) { return(0); } sql.Append(getFieldString_SqlServer(schemaDrs)); } sql.AppendFormat("CONSTRAINT [PK_{0}] PRIMARY KEY CLUSTERED ([{1}] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]", dbe.Name, jsonData["primarykey"].ToString()); } catch (SqlException ex) { } } //create table into the system database return(dataDBExtract.ExecuteStatement(sql.ToString())); }