sqlite estatestore: stop using sqlite autoincrement on estateID, look for max value in USE instead. This is slow, but the db should be small; fix min value to 101 ( we should allow special lower values, but not now )

This commit is contained in:
UbitUmarov
2021-08-27 16:21:03 +01:00
parent 5a5c89bc49
commit b363d1f9ee
2 changed files with 17 additions and 19 deletions

View File

@@ -189,15 +189,25 @@ namespace OpenSim.Data.SQLite
{
List<string> names = new List<string>(FieldList);
// Remove EstateID and use AutoIncrement
if (es.EstateID < 100)
names.Remove("EstateID");
using (SqliteCommand cmd = m_connection.CreateCommand())
{
string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
if (es.EstateID < 100)
{
cmd.CommandText = "select MAX(EstateID) FROM estate_settings";
cmd.Parameters.Clear();
uint a = 0;
object r = cmd.ExecuteScalar();
if(r!=null && !(r is DBNull))
{
a = Convert.ToUInt32(r);
}
if (a < 100)
a = 100;
++a;
es.EstateID = a;
}
cmd.CommandText = sql;
cmd.CommandText = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
cmd.Parameters.Clear();
foreach (string name in FieldList)
@@ -216,18 +226,6 @@ namespace OpenSim.Data.SQLite
}
cmd.ExecuteNonQuery();
// Only get Auto ID if we actually used it else we just get 0
if (es.EstateID < 100)
{
cmd.CommandText = "select LAST_INSERT_ROWID() as id";
cmd.Parameters.Clear();
using (IDataReader r = cmd.ExecuteReader())
{
r.Read();
es.EstateID = Convert.ToUInt32(r["id"]);
}
}
}
}