Ejemplo n.º 1
0
 public void Delete(Sql sql, Connection db, Action<int> callback = null)
 {
     ExecuteNonQuery(sql, db, callback);
 }
Ejemplo n.º 2
0
 public void ExecuteNonQuery(Sql sql, Connection db, Action<int> callback = null)
 {
     var query = new SQLiteQuery
     {
         Sql = sql,
         Connection = db,
         CallbackNonQuery = callback,
         NonQuery = true
     };
     lock (_syncroot) _queue.Enqueue(query);
     _workevent.Set();
 }
Ejemplo n.º 3
0
 public void CloseDb(Connection db)
 {
     if (db == null) return;
     _connections.Remove(db.ConnectionString);
     if (db.Plugin != null && _connections.Values.All(c => c.Plugin != db.Plugin))
     {
         Event.Callback<Plugin, PluginManager> event_callback;
         if (_pluginRemovedFromManager.TryGetValue(db.Plugin, out event_callback))
         {
             event_callback.Remove();
             _pluginRemovedFromManager.Remove(db.Plugin);
         }
     }
     db.Con?.Close();
     db.Plugin = null;
 }
Ejemplo n.º 4
0
 public void Query(Sql sql, Connection db, Action<List<Dictionary<string, object>>> callback)
 {
     var query = new SQLiteQuery
     {
         Sql = sql,
         Connection = db,
         Callback = callback
     };
     lock (_syncroot) _queue.Enqueue(query);
     _workevent.Set();
 }
Ejemplo n.º 5
0
 public Connection OpenDb(string file, Plugin plugin, bool persistent = false)
 {
     if (string.IsNullOrEmpty(file)) return null;
     var filename = Path.Combine(_dataDirectory, file);
     if (!filename.StartsWith(_dataDirectory, StringComparison.Ordinal))
         throw new Exception("Only access to oxide directory!");
     var conStr = $"Data Source={filename};Version=3;";
     Connection connection;
     if (_connections.TryGetValue(conStr, out connection))
     {
         if (plugin != connection.Plugin)
         {
             Interface.Oxide.LogWarning("Already open connection ({0}), by plugin '{1}'...", conStr, connection.Plugin);
             return null;
         }
         Interface.Oxide.LogWarning("Already open connection ({0}), using existing instead...", conStr);
     }
     else
     {
         connection = new Connection(conStr, persistent)
         {
             Plugin = plugin,
             Con = new SQLiteConnection(conStr)
         };
         _connections[conStr] = connection;
     }
     if (plugin != null && !_pluginRemovedFromManager.ContainsKey(plugin))
         _pluginRemovedFromManager[plugin] = plugin.OnRemovedFromManager.Add(OnRemovedFromManager);
     return connection;
 }