public override bool CreateTable(IFreeDocument example, string name) { if (string.IsNullOrEmpty(name)) { throw new Exception("数据库表名不能为空"); } var txt = example.DictSerialize(Scenario.Database); var sb = string.Join(",", txt.Select(d => $"{d.Key} {DataTypeConverter.ToType(d.Value)}")); var sql = $"CREATE TABLE {GetTableName(name)} ({sb})"; ExecuteNonQuery(sql); RefreshTableNames(); return(true); }
public virtual bool CreateTable(IFreeDocument example, string name) { FreeDocument txt = example.DictSerialize(Scenario.Database); var sb = new StringBuilder(); foreach (var o in txt) { sb.Append(o.Key); sb.AppendFormat(" {0}, ", DataTypeConverter.ToType(o.Value)); } sb.Remove(sb.Length - 1, 1); string sql = $"CREATE TABLE {GetTableName(name)} ({sb})"; ExecuteNonQuery(sql); RefreshTableNames(); return(true); }
public override bool CreateTable(IFreeDocument example, string name) { if (string.IsNullOrEmpty(name)) { throw new Exception(GlobalHelper.Get("key_29")); } var txt = example.DictSerialize(); var sb = string.Join(",", txt.Select(d => $"{d.Key} {DataTypeConverter.ToType(d.Value)}")); var sql = $"CREATE TABLE {GetTableName(name)} ({sb});"; ExecuteNonQuery(sql); RefreshTableNames(); if (TableNames.Collection.FirstOrDefault(d => d.Name == name) == null) { return(false); } return(true); }
public override void BatchInsert(IEnumerable <IFreeDocument> source, string dbTableName) { using (var cnn = new SQLiteConnection(ConnectionString)) { cnn.Open(); using (var mytrans = cnn.BeginTransaction()) { foreach (var data in source.Init(d => { if (TableNames.Collection.FirstOrDefault(d2 => d2.Name == dbTableName) == null) { var txt = d.DictSerialize(Scenario.Database); var sb = string.Join(",", txt.Select(d2 => $"{d2.Key} {DataTypeConverter.ToType(d2.Value)}")); var sql = $"CREATE TABLE {GetTableName(dbTableName)} ({sb})"; ExecuteNonQuery(sql, cnn); } return(true); })) { try { var sql = Insert(data, dbTableName); var mycommand = new SQLiteCommand(sql, cnn, mytrans); mycommand.CommandTimeout = 180; mycommand.ExecuteNonQuery(); } catch (Exception ex) { XLogSys.Print.Warn($"insert sqllite database error {ex.Message}"); } } mytrans.Commit(); cnn.Close(); } } }
public virtual bool CreateTable(IFreeDocument example, string name) { if (string.IsNullOrEmpty(name)) { throw new Exception(GlobalHelper.Get("key_29")); } FreeDocument txt = example.DictSerialize(Scenario.Database); var sb = string.Join(",", txt.Select(d => $"{ ScriptHelper.RemoveSpecialCharacter(d.Key)} {DataTypeConverter.ToType(d.Value)}")); string sql = $"CREATE TABLE {GetTableName(name)} ({sb})"; ExecuteNonQuery(sql); RefreshTableNames(); return(true); }