Browse Source

fixed autoincrement sqlcode (in sqlite, is autoincrement not auto_increment) in diffrent database

master
jkpete 2 months ago
parent
commit
16a36ae387
  1. 9
      addons/EGFramework/Module/Extension/EGSqlExtension.cs
  2. 5
      addons/EGFramework/Module/SaveTools/Data/EGDapper.cs
  3. 5
      addons/EGFramework/Module/SaveTools/Data/EGSqliteSave.cs

9
addons/EGFramework/Module/Extension/EGSqlExtension.cs

@ -107,8 +107,7 @@ namespace EGFramework @@ -107,8 +107,7 @@ namespace EGFramework
}
return sqlCommand;
}
public static string ToCreateTableSQL(this Type type, string tableName)
public static string ToCreateTableSQL(this Type type, string tableName,string idType = "INTEGER PRIMARY KEY AUTO_INCREMENT")
{
var properties = type.GetProperties();
FieldInfo[] fields = type.GetFields();
@ -123,12 +122,12 @@ namespace EGFramework @@ -123,12 +122,12 @@ namespace EGFramework
}
keySet = keySet.TrimEnd(',');
string createSql = @"CREATE TABLE " + tableName + " (" +
"`ID` INTEGER PRIMARY KEY AUTO_INCREMENT, " + keySet
"`ID` "+idType+", " + keySet
+ ");";
return createSql;
}
public static string ToCreateTableSQL(this Dictionary<string,Type> tableParam,string tableName)
public static string ToCreateTableSQL(this Dictionary<string,Type> tableParam,string tableName,string idType = "INTEGER PRIMARY KEY AUTO_INCREMENT")
{
string keySet = "";
@ -137,7 +136,7 @@ namespace EGFramework @@ -137,7 +136,7 @@ namespace EGFramework
}
keySet = keySet.TrimEnd(',');
string createSql = @"CREATE TABLE "+tableName+" ("+
"`ID` INTEGER PRIMARY KEY AUTOINCREMENT, "+keySet
"`ID` "+idType+", "+keySet
+");";
return createSql;
}

5
addons/EGFramework/Module/SaveTools/Data/EGDapper.cs

@ -11,6 +11,7 @@ namespace EGFramework @@ -11,6 +11,7 @@ namespace EGFramework
public abstract class EGDapper : IEGSave, IEGSaveData, IEGDataBase
{
public DbConnection Connection { get; set; }
public string PrimaryType = "INTEGER PRIMARY KEY AUTO_INCREMENT";
public string ExceptionMsg;
public abstract void InitSave(string conn);
@ -303,7 +304,7 @@ namespace EGFramework @@ -303,7 +304,7 @@ namespace EGFramework
EG.Print("Table " + dataKey + " has been created!");
return;
}
string createSql = typeof(TData).ToCreateTableSQL(dataKey);
string createSql = typeof(TData).ToCreateTableSQL(dataKey,PrimaryType);
int count = Connection.Execute(createSql);
}
@ -319,7 +320,7 @@ namespace EGFramework @@ -319,7 +320,7 @@ namespace EGFramework
{
tableType.Add(pair.Key, pair.Value.GetType());
}
string createSql = tableType.ToCreateTableSQL(dataKey);
string createSql = tableType.ToCreateTableSQL(dataKey,PrimaryType);
int count = Connection.Execute(createSql);
}

5
addons/EGFramework/Module/SaveTools/Data/EGSqliteSave.cs

@ -16,10 +16,7 @@ namespace EGFramework{ @@ -16,10 +16,7 @@ namespace EGFramework{
/// <param name="path">please add *.db suffix or your db file suffix</param>
public override void InitSave(string path)
{
if (!File.Exists(path))
{
Directory.CreateDirectory(path);
}
PrimaryType = "INTEGER PRIMARY KEY AUTOINCREMENT";
InitDatabase(path);
}

Loading…
Cancel
Save