internal virtual string GetSqlFromTableInfo(SqlTableInfo sql) { SqlFieldList fieldList = new SqlFieldList(sql.TableName); fieldList.PrividerType = CurrPrividerType; foreach (var item in sql.Fields) { if (item.Key == "OBJECTID") { continue;// “OBJECTID”是自增树列,会出现 SQL 语句无法更新标识列 2019/07/29 } bool IsPkField = false; if (!string.IsNullOrEmpty(sql.KeyFieldName)) { IsPkField = item.Key.ToLower() == sql.KeyFieldName.ToLower(); } if (IsPkField) { fieldList.PrimaryField = new SqlField(item.Key, item.Value, CurrPrividerType); } if (CurrPrividerType == SqlPrividerType.Sqlite) { if (item.Value is DateTime) { string str = ((DateTime)item.Value).ToString("s"); fieldList.AddNonPrimaryField(item.Key, str); } else { fieldList.AddNonPrimaryField(item.Key, item.Value); } } else { if (!DicTableToTableNameFields[sql.TableName].ContainsKey(item.Key)) { continue; } var typeName = DicTableToTableNameFields[sql.TableName][item.Key]; if (typeName == "datetime" && item.Value != null && !string.IsNullOrEmpty(item.Value.ToString())) { var date = DateTime.Parse(item.Value.ToString()); fieldList.AddNonPrimaryField(item.Key, date); } else { fieldList.AddNonPrimaryField(item.Key, item.Value); } } continue; } return(SqlFieldList.GetSqlString(fieldList)); }
/// <summary> /// 更新sql拼接 /// </summary> /// <param name="sqlFieldList"></param> /// <returns></returns> public static string GetUpdateSqlString(SqlFieldList sqlFieldList) { StringBuilder sb = new StringBuilder(); if (sqlFieldList.PrividerType == SqlPrividerType.SqlClient) { if (sqlFieldList.PrimaryField == null) { return(sqlFieldList.GetInsertString()); } //sb.Append(" IF EXISTS ("); //sb.Append(Environment.NewLine); //sb.Append(sqlFieldList.GetSelectString()); //sb.Append(Environment.NewLine); //sb.Append(") "); //sb.Append(Environment.NewLine); ////sb.Append(" BEGIN ") ; //sb.Append(Environment.NewLine); sb.Append(sqlFieldList.GetUpdateString()); sb.Append(Environment.NewLine); //sb.Append(" END ") ; //sb.Append(Environment.NewLine); //sb.Append(" ELSE "); //sb.Append(Environment.NewLine); //sb.Append(Environment.NewLine); //sb.Append(sqlFieldList.GetInsertString()); //sb.Append(Environment.NewLine); return(sb.ToString()); } else if (sqlFieldList.PrividerType == SqlPrividerType.MySqlClient || sqlFieldList.PrividerType == SqlPrividerType.Sqlite) { sb.Append(sqlFieldList.GetReplaceString()); sb.Append(Environment.NewLine); return(sb.ToString()); } else { return(null); } }
internal virtual string GetSqlFromDelTableInfo(SqlTableInfo sql) { SqlFieldList fieldList = new SqlFieldList(sql.TableName); foreach (var item in sql.Fields) { bool IsPkField = false; if (!string.IsNullOrEmpty(sql.KeyFieldName)) { IsPkField = item.Key == sql.KeyFieldName; } if (IsPkField) { fieldList.PrimaryField = new SqlField(item.Key, item.Value, CurrPrividerType); } fieldList.AddNonPrimaryField(item.Key, item.Value); continue; } return(fieldList.GetDeleteString()); }