/// <summary>
        /// Takes a GIS model and a file and writes the model to that file.
        /// </summary>
        /// <param name="model">
        /// The GisModel which is to be persisted.
        /// </param>
        /// <param name="fileName">
        /// The name of the file in which the model is to be persisted.
        /// </param>
        public void Persist(GisModel model, string fileName)
        {
            Initialize(model);
            PatternedPredicate[] predicates = GetPredicates();

            if (	File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            using (mDataConnection = new SQLiteConnection("Data Source=" + fileName + ";New=True;Compress=False;Synchronous=Off;UTF8Encoding=True;Version=3"))
            {
                mDataConnection.Open();
                mDataCommand = mDataConnection.CreateCommand();
                CreateDataStructures();

                using (mDataTransaction = mDataConnection.BeginTransaction())
                {
                    mDataCommand.Transaction = mDataTransaction;

                    CreateModel(model.CorrectionConstant, model.CorrectionParameter);
                    InsertOutcomes(model.GetOutcomeNames());
                    InsertPredicates(predicates);
                    InsertPredicateParameters(model.GetOutcomePatterns(), predicates);

                    mDataTransaction.Commit();
                }
                mDataConnection.Close();
            }
        }
Exemplo n.º 2
0
 public void open()
 {
     SetConnection();
     sql_con.Open();
     _sqLiteTransaction = sql_con.BeginTransaction();
     sql_cmd = sql_con.CreateCommand();
 }
 public SQLiteTransaction(SQLiteDatabase database, IsolationLevel level, SQLiteSettings settings)
 {
     _database    = database;
     _settings    = settings;
     _connection  = _database.ConnectionPool.GetConnection();
     _transaction = _connection.BeginTransaction(level);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Run the list command for input connection
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="list"></param>
        void RunSqlCommand(System.Data.SQLite.SQLiteConnection connection, List <string> list)
        {
            int i = 0;

            using (System.Data.SQLite.SQLiteTransaction trans = connection.BeginTransaction())
            {
                System.Data.SQLite.SQLiteCommand command = new System.Data.SQLite.SQLiteCommand(connection);
                foreach (string commandText in list)
                {
                    try
                    {
                        if (commandText.Trim().Length == 0)
                        {
                            continue;
                        }
                        command.CommandText = commandText;
                        command.ExecuteNonQuery();
                        i++;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                trans.Commit();
            }

            list.Clear();
        }
Exemplo n.º 5
0
 public SQLiteTransaction(SQLiteDatabase database, IsolationLevel level, SQLiteSettings settings)
 {
   _database = database;
   _settings = settings;
   _connection = _database.ConnectionPool.GetConnection();
   _transaction = _connection.BeginTransaction(level);
 }
		public SQLiteCommand(string commandText, SQLiteConnection connection, SQLiteTransaction transaction)
		{
			CommandText = commandText;
			DbConnection = connection;
			DbTransaction = transaction;
			m_parameterCollection = new SQLiteParameterCollection();
		}
Exemplo n.º 7
0
 public AbstractDatabase(string db_path)
 {
     conn_        = new SQLiteConnection("Data Source=" + db_path);
     tables_      = new Dictionary <string, AbstractTable>();
     transaction_ = null;
     DBFilePath   = db_path;
 }
    ///////////////////////////////////////////////////////////////////////////////////////////////

    private /* protected virtual */ void Dispose(bool disposing)
    {
        if (!disposed)
        {
            if (disposing)
            {
                ////////////////////////////////////
                // dispose managed resources here...
                ////////////////////////////////////

                if (_transaction != null)
                {
                    _transaction.Dispose();
                    _transaction = null;
                }

                if (_scope != null)
                {
                    // _scope.Dispose(); // NOTE: Not "owned" by us.
                    _scope = null;
                }
            }

            //////////////////////////////////////
            // release unmanaged resources here...
            //////////////////////////////////////

            disposed = true;
        }
    }
Exemplo n.º 9
0
 public void CommitTransaction()
 {
     globalTransaction.Commit();
     globalTransaction.Dispose();
     globalTransaction = null;
     Close();
 }
    internal SQLiteEnlistment(SQLiteConnection cnn, Transaction scope)
    {
      _transaction = cnn.BeginTransaction();
      _scope = scope;

      _scope.EnlistVolatile(this, System.Transactions.EnlistmentOptions.None);
    }
Exemplo n.º 11
0
        public SQLiteCommand GetCommandOnCurrentConnect(String commandText, out SQLiteTransaction sqLiteTransaction){
            var connection = GetCurrentConnection();

            sqLiteTransaction = connection.BeginTransaction();

            return new SQLiteCommand(commandText, connection, sqLiteTransaction);
        }
Exemplo n.º 12
0
        internal static void PrepareCommand(SQLiteCommand command, SQLiteConnection connection, SQLiteTransaction transaction,
                                           CommandType commandType, string commandText, SQLiteParameter[] commandParameters,
                                           out bool mustCloseConnection)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (string.IsNullOrEmpty(commandText)) throw new ArgumentNullException("commandText");

            if (connection.State == ConnectionState.Open)
                mustCloseConnection = false;
            else
            {
                mustCloseConnection = true;
                connection.Open();
            }

            command.Connection = connection;
            command.CommandText = commandText;

            if (transaction != null)
            {
                if (transaction.Connection == null)
                    throw new ArgumentException(
                        "The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
                command.Transaction = transaction;
            }

            command.CommandType = commandType;

            if (commandParameters != null)
                AttachParameters(command, commandParameters);
            return;
        }
Exemplo n.º 13
0
        public SQLiteCommand CreateAddProductCommand(SQLiteConnection conn, SQLiteTransaction transaction)
        {
            var cmd = new SQLiteCommand(_sql, conn, transaction);
            CreateParameters(cmd);

            return cmd;
        }
Exemplo n.º 14
0
		protected long ExecuteNonQuery(
			string                       sql,
			IEnumerable<SQLiteParameter> parameters,
			SQLiteTransaction            transaction = null
		)
		{
			long iRows = 0L;

			this.Logger.DebugFormat("Datasource:'{0}';sql:'{1}'",
				this.Connection.DataSource,
				sql
			);

			using (SQLiteCommand command = this.GetCommand(sql, transaction))
			{
				if (parameters != null)
				{
					foreach (SQLiteParameter parameter in parameters)
					{
						command.Parameters.Add(parameter);
					}
				}

				iRows = command.ExecuteNonQuery();
			}

			// this.Logger.DebugFormat("ExecuteNonQuery:ExecuteNonQuery:sql:'{0}';rows:'{1}'",
			//    sql,
			//    iRows
			// );

			return iRows;
		}
Exemplo n.º 15
0
        public Transaction(SQLiteTransaction transaction)
        {
            if (_base == null)
                throw new ArgumentNullException("transaction");

            _base = transaction;
        }
Exemplo n.º 16
0
 /// <summary>
 /// 更新数据库
 /// </summary>
 /// <param name="sql">数据库语句</param>
 public static void SQLUpdate(string sql)
 {
     using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
     {
         conn.Open();  // 连接数据库
         using (System.Data.SQLite.SQLiteTransaction trans = conn.BeginTransaction())
         {
             using (SQLiteCommand cmd = new SQLiteCommand(conn))
             {
                 //事务处理
                 cmd.Transaction = trans;
                 try
                 {
                     cmd.CommandText = sql;
                     cmd.ExecuteNonQuery();
                     trans.Commit();
                 }
                 catch (Exception)
                 {
                     trans.Rollback();
                 }
             }
         }
     }
 }
Exemplo n.º 17
0
 public void CommitTran()
 {
     if (_tran != null)
     {
         _tran.Commit();
         _tran = null;
     }
 }
Exemplo n.º 18
0
		private SQLiteCommand GetCommand(string sql, SQLiteTransaction transaction)
		{
			return new SQLiteCommand(
				sql,
				this.Connection,
				transaction
			);
		}
 public void Begin(IsolationLevel level)
 {
     if (_transaction != null)
     {
         _transaction.Rollback();
     }
     _transaction = _connection.BeginTransaction(IsolationLevel.Serializable);
 }
Exemplo n.º 20
0
            private void init(string connString) {

                connection = new SQLiteConnection(connString);
                connection.Open();
                //connection.ChangeDatabase(Server.MySQLDatabaseName);

                transaction = connection.BeginTransaction();
            }
    private void Cleanup(SQLiteConnection cnn)
    {
      if (_disposeConnection)
        cnn.Dispose();

      _transaction = null;
      _scope = null;
    }
Exemplo n.º 22
0
		public void SetCommandConstraints(
			string                       clause,
			IEnumerable<SQLiteParameter> parameters,
			SQLiteTransaction            transaction = null
		)
		{
			this._clause      = clause;
			this._parameters  = parameters;
			this._transaction = transaction;
		}
Exemplo n.º 23
0
 /// <summary>
 ///     Default Constructor for SQLiteDatabase Class.
 /// </summary>
 /// <param name="transaction">Allow programmers to insert, update and delete values in one transaction</param>
 public SQLiteDatabase(bool transaction = false)
 {
     _transaction = transaction;
     DBConnection = "Data Source=" + System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/eCrit.db") + ";Verson=3;";
     if (transaction)
     {
         _sqLiteConnection = new SQLiteConnection(DBConnection);
         _sqLiteConnection.Open();
         _sqLiteTransaction = _sqLiteConnection.BeginTransaction();
     }
 }
        //开始一个事务处理
        public void beginTrans()
        {
            try
            {
                tran = conn.BeginTransaction();
            }
            catch (System.Exception ex)
            {

            }
        }
Exemplo n.º 25
0
 //initiates the the beginning of the transaction (any subsequent database operations
 //  will be rolled back if any error occurs before the changes are committed)
 public static void beginTransaction()
 {
     lock (threadLock) {
         try {
             transaction = connection.BeginTransaction();
         }
         catch (SQLiteException error) {
             Util.logError(error.Message);
         }
     }
 }
 public override void Rollback()
 {
     if (IsDisposed)
         throw new ObjectDisposedException(this.GetType().ToString());
     SQLiteConnection cnn = _transaction.Connection;
     _transaction.Rollback();
     if (cnn != null && cnn.State != System.Data.ConnectionState.Closed)
         cnn.Close();
     _transaction = null;
     cnn = null;
 }
Exemplo n.º 27
0
        public SQLiteTransaction(SQLiteDatabase database, IsolationLevel level, SQLiteSettings settings)
        {
            _database = database;
            _settings = settings;
#if NO_POOL
            _connection = _database.CreateOpenAndInitializeConnection();
#else
            _connection = _database.ConnectionPool.GetConnection();
#endif
            _transaction = _connection.BeginTransaction(level);
        }
Exemplo n.º 28
0
        public SQLiteMonTransaction(SQLiteTransaction transaction)
        {
            this.wrappedTrans = transaction;

            StackTrace trace = new StackTrace(true);

            lock (readerInfoLock)
            {
                readerInfo.Add(this.wrappedTrans, trace.ToString());
            }
        }
Exemplo n.º 29
0
        public DbTransaction()
        {
            if (CurrentTransaction != null)
                throw new ApplicationException("There is another transaction active on this thread!");

            SQLiteConnection conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString);
            conn.Open();
            _transaction = conn.BeginTransaction();

            CurrentTransaction = this;
        }
Exemplo n.º 30
0
 public void beginTransaction()
 {
     try
     {
         transaction = connection.BeginTransaction();
         command.Transaction = transaction;
     }
     catch (Exception myExp)
     {
         throw myExp;
     }
 }
Exemplo n.º 31
0
        public void ExecuteNonQuery(string query, SQLiteTransaction trans, params Tuple<string,string>[] parameters)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(query, connection,trans))
            {
                foreach (var p in parameters)
                {
                    cmd.Parameters.Add(p.Item1, DbType.String).Value = p.Item2;
                }

                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 32
0
		public ReplaceCommand(
			SQLiteConnection  connection,
			TableDefinition   tableDefinition,
			SQLiteTransaction transaction = null
		) : base(
				connection,
				tableDefinition
			)
		{
			this._rows        = new List<ITableRow>();
			this._transaction = transaction;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="SetJobLastKnownEventCommand" /> class.
 /// </summary>
 /// <param name="jobName">Name of the job.</param>
 /// <param name="jobEventTime">The time.</param>
 /// <param name="jobScheduledTime">The job scheduled time.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="transaction">The transaction.</param>
 public SetJobLastKnownEventCommand(string jobName, 
     DateTimeOffset jobEventTime, 
     DateTimeOffset jobScheduledTime, 
     SQLiteConnection connection,
     SQLiteTransaction transaction)
 {
     JobName = jobName;
     JobEventTime = jobEventTime;
     JobScheduledTime = jobScheduledTime;
     Connection = connection;
     Transaction = transaction;
 }
Exemplo n.º 34
0
        public void InsereExtensao(ExtensaoModel _extensao, SQLiteTransaction _dbTransaction = null)
        {
            string strSQL = string.Format("INSERT INTO EXTENSAO (EXTENSAO) VALUES ('{0}')",
                                                             _extensao);

            m_dbHelper.Connection.Open();
            using (SQLiteCommand cmd = new SQLiteCommand(strSQL, m_dbHelper.Connection))
            {
                cmd.ExecuteNonQuery();
            }
            m_dbHelper.Connection.Close();
        }
Exemplo n.º 35
0
		public RowDeleteCommand(
			SQLiteConnection connection,
			TableDefinition  tableDefinition
		) : base(
				connection,
				tableDefinition
			)
		{
			this._clause      = null;
			this._parameters  = null;
			this._transaction = null;
		}
 protected override void OnDispose()
 {
     if (_transaction != null)
     {
         SQLiteConnection cnn = _transaction.Connection;
         _transaction.Rollback();
         if (cnn != null && cnn.State != System.Data.ConnectionState.Closed)
             cnn.Close();
         _transaction = null;
         cnn = null;
     }
 }
Exemplo n.º 37
0
 /// <summary>
 /// Commence une transaction sql isolée
 /// ATTENTION LES OUVERTURES ET FERMETURES DE LA BASE NE SERONT PLUS AUTOMATIQUES
 /// </summary>
 public override bool BeginTransaction(string transactionName = null)
 {
     if (conn == null)
     {
         this.Open();
     }
     if (this.transac != null)
     {
         return(false);                      // postgres authorise qu'une transaction
     }
     transac = conn.BeginTransaction();
     return(true);
 }
Exemplo n.º 38
0
 public override bool CommitTransaction(string transactionName = null)
 {
     if (conn == null)
     {
         return(false);
     }
     if (transac == null)
     {
         return(false);
     }
     transac.Commit();
     transac.Dispose();
     transac = null;
     return(true);
 }
Exemplo n.º 39
0
 public override bool RollBackTransaction(string transactionName = null)
 {
     if (conn == null)
     {
         return(false);
     }
     if (transac == null)
     {
         return(false);
     }
     transac.Rollback();
     transac.Dispose();
     transac = null;
     return(true);
 }
Exemplo n.º 40
0
        public void Dispose()
        {
            // Dispose the System.Data.SQLite.SQLiteTransaction. If neither Commit nor Rollback was
            // called before, the standard behaviour of System.Data.SQLite.SQLiteTransaction is to
            // issue a Rollback during disposing.
            if (_transaction != null)
            {
                _transaction.Dispose();
                _transaction = null;
            }

            // Return the underlying connection to the connection pool without closing it
            if (_connection != null)
            {
                _database.ConnectionPool.PutConnection(_connection);
                _connection = null;
            }
        }
Exemplo n.º 41
0
 public void CommitTransaction()
 {
     transaction_.Commit();
     transaction_ = null;
 }
Exemplo n.º 42
0
 /// <summary>
 /// Execute Entities
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="commandType"></param>
 /// <param name="transaction"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static IEnumerable <T> ExecuteEntities <T>(this SQLiteConnection conn, string cmdText, CommandType commandType, SQLiteTransaction transaction) where T : new()
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteEntities <T>(cmdText, null, commandType, transaction));
 }
 /// <summary>
 /// Execute scalar as
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="parameters"></param>
 /// <param name="commandType"></param>
 /// <param name="transaction"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T ExecuteScalarAs <T>(this SQLiteConnection conn, string cmdText, SQLiteParameter[] parameters, CommandType commandType, SQLiteTransaction transaction)
 {
     conn.CheckNull(nameof(conn));
     using var command = conn.CreateCommand(cmdText, commandType, transaction, parameters);
     return((T)command.ExecuteScalar());
 }
Exemplo n.º 44
0
        /// <summary>
        /// Adds the specified user names to the specified roles for the configured applicationName.
        /// </summary>
        /// <param name="usernames">A string array of user names to be added to the specified roles.</param>
        /// <param name="roleNames">A string array of the role names to add the specified user names to.</param>
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            foreach (string roleName in roleNames)
            {
                if (!RoleExists(roleName))
                {
                    throw new ProviderException("Role name not found.");
                }
            }

            foreach (string username in usernames)
            {
                if (username.IndexOf(',') > 0)
                {
                    throw new ArgumentException("User names cannot contain commas.");
                }

                foreach (string RoleName in roleNames)
                {
                    if (IsUserInRole(username, RoleName))
                    {
                        throw new ProviderException("User is already in role.");
                    }
                }
            }

            SQLiteTransaction tran = null;
            SQLiteConnection  cn   = GetDBConnectionForRole();

            try
            {
                if (cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                }

                if (!IsTransactionInProgress())
                {
                    tran = cn.BeginTransaction();
                }

                using (SQLiteCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = "INSERT INTO " + USERS_IN_ROLES_TB_NAME
                                      + " (UserId, RoleId)"
                                      + " SELECT u.UserId, r.RoleId"
                                      + " FROM " + USER_TB_NAME + " u, " + ROLE_TB_NAME + " r"
                                      + " WHERE (u.LoweredUsername = $Username) AND (u.ApplicationId = $ApplicationId)"
                                      + " AND (r.LoweredRoleName = $RoleName) AND (r.ApplicationId = $ApplicationId)";

                    SQLiteParameter userParm = cmd.Parameters.Add("$Username", DbType.String, MAX_USERNAME_LENGTH);
                    SQLiteParameter roleParm = cmd.Parameters.Add("$RoleName", DbType.String, MAX_ROLENAME_LENGTH);
                    cmd.Parameters.AddWithValue("$ApplicationId", _applicationId);

                    foreach (string username in usernames)
                    {
                        foreach (string roleName in roleNames)
                        {
                            userParm.Value = username.ToLowerInvariant();
                            roleParm.Value = roleName.ToLowerInvariant();
                            cmd.ExecuteNonQuery();
                        }
                    }

                    // Commit the transaction if it's the one we created in this method.
                    if (tran != null)
                    {
                        tran.Commit();
                    }
                }
            }
            catch
            {
                if (tran != null)
                {
                    tran.Rollback();
                }
                throw;
            }
            finally
            {
                if (tran != null)
                {
                    tran.Dispose();
                }

                if (!IsTransactionInProgress())
                {
                    cn.Dispose();
                }
            }
        }
Exemplo n.º 45
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="dbCommand">The current sql command.</param>
        /// <param name="commandText">The command text to execute.</param>
        /// <param name="commandType">The command type.</param>
        /// <param name="connectionString">The connection string to use.</param>
        /// <param name="values">The collection of sql parameters to include.</param>
        /// <returns>-1 if command execution failed.</returns>
        public Int32 ExecuteCommand(ref DbCommand dbCommand, string commandText,
                                    CommandType commandType, string connectionString, params DbParameter[] values)
        {
            // Initial connection objects.
            dbCommand = null;
            Int32 returnValue = -1;

            SqliteClient.SQLiteConnection  sqlConnection  = null;
            SqliteClient.SQLiteTransaction sqlTransaction = null;

            try
            {
                // Create a new connection.
                using (sqlConnection = new SqliteClient.SQLiteConnection(connectionString))
                {
                    // Open the connection.
                    sqlConnection.Open();

                    // Start a new transaction.
                    sqlTransaction = sqlConnection.BeginTransaction();

                    // Create the command and assign any parameters.
                    dbCommand = new SqliteClient.SQLiteCommand(DataTypeConversion.GetSqlConversionDataTypeNoContainer(
                                                                   ConnectionContext.ConnectionDataType.SqlDataType, commandText), sqlConnection);
                    dbCommand.CommandType = commandType;
                    dbCommand.Transaction = sqlTransaction;

                    if (values != null)
                    {
                        foreach (SqliteClient.SQLiteParameter sqlParameter in values)
                        {
                            dbCommand.Parameters.Add(sqlParameter);
                        }
                    }

                    // Execute the command.
                    returnValue = dbCommand.ExecuteNonQuery();

                    // Commit the transaction.
                    sqlTransaction.Commit();

                    // Close the database connection.
                    sqlConnection.Close();
                }

                // Return true.
                return(returnValue);
            }
            catch (Exception ex)
            {
                try
                {
                    // Attempt to roll back the transaction.
                    if (sqlTransaction != null)
                    {
                        sqlTransaction.Rollback();
                    }
                }
                catch { }

                // Throw a general exception.
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (sqlConnection != null)
                {
                    sqlConnection.Close();
                }
            }
        }
 /// <summary>
 /// Execute ExpandoObjects
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="commandType"></param>
 /// <param name="transaction"></param>
 /// <returns></returns>
 public static IEnumerable <dynamic> ExecuteExpandoObjects(this SQLiteConnection conn, string cmdText, CommandType commandType, SQLiteTransaction transaction)
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteExpandoObjects(cmdText, null, commandType, transaction));
 }
Exemplo n.º 47
0
 internal SQLiteEnlistment(SQLiteConnection cnn)
 {
     _transaction = cnn.BeginTransaction();
     _transaction.Connection._enlisted = true;
 }
Exemplo n.º 48
0
 public void BeginTransaction()
 {
     transaction_ = conn_.BeginTransaction();
 }
Exemplo n.º 49
0
        /// <summary>
        /// Removes the specified user names from the specified roles for the configured applicationName.
        /// </summary>
        /// <param name="usernames">A string array of user names to be removed from the specified roles.</param>
        /// <param name="roleNames">A string array of role names to remove the specified user names from.</param>
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            foreach (string roleName in roleNames)
            {
                if (!RoleExists(roleName))
                {
                    throw new ProviderException("Role name not found.");
                }
            }

            foreach (string username in usernames)
            {
                foreach (string roleName in roleNames)
                {
                    if (!IsUserInRole(username, roleName))
                    {
                        throw new ProviderException("User is not in role.");
                    }
                }
            }

            SQLiteTransaction tran = null;
            SQLiteConnection  cn   = GetDBConnectionForRole();

            try
            {
                if (cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                }

                if (!IsTransactionInProgress())
                {
                    tran = cn.BeginTransaction();
                }

                using (SQLiteCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM " + USERS_IN_ROLES_TB_NAME
                                      + " WHERE UserId = (SELECT UserId FROM " + USER_TB_NAME + " WHERE LoweredUsername = $Username AND ApplicationId = $ApplicationId)"
                                      + " AND RoleId = (SELECT RoleId FROM " + ROLE_TB_NAME + " WHERE LoweredRoleName = $RoleName AND ApplicationId = $ApplicationId)";

                    SQLiteParameter userParm = cmd.Parameters.Add("$Username", DbType.String, MAX_USERNAME_LENGTH);
                    SQLiteParameter roleParm = cmd.Parameters.Add("$RoleName", DbType.String, MAX_ROLENAME_LENGTH);
                    cmd.Parameters.AddWithValue("$ApplicationId", _applicationId);

                    foreach (string username in usernames)
                    {
                        foreach (string roleName in roleNames)
                        {
                            userParm.Value = username.ToLowerInvariant();
                            roleParm.Value = roleName.ToLowerInvariant();
                            cmd.ExecuteNonQuery();
                        }
                    }

                    // Commit the transaction if it's the one we created in this method.
                    if (tran != null)
                    {
                        tran.Commit();
                    }
                }
            }
            catch
            {
                if (tran != null)
                {
                    tran.Rollback();
                }

                throw;
            }
            finally
            {
                if (tran != null)
                {
                    tran.Dispose();
                }

                if (!IsTransactionInProgress())
                {
                    cn.Dispose();
                }
            }
        }
 /// <summary>
 /// Execute scalar as
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="parameters"></param>
 /// <param name="transaction"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static Task <T> ExecuteScalarAsAsync <T>(this SQLiteConnection conn, string cmdText, SQLiteParameter[] parameters, SQLiteTransaction transaction)
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteScalarAsAsync <T>(cmdText, parameters, CommandType.Text, transaction));
 }
 ExecuteExpandoObjectsAsync(this SQLiteConnection conn, string cmdText, SQLiteParameter[] parameters, SQLiteTransaction transaction)
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteExpandoObjectsAsync(cmdText, parameters, CommandType.Text, transaction));
 }
 /// <summary>
 /// Execute DataSet
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="transaction"></param>
 /// <returns></returns>
 public static DataSet ExecuteDataSet(this SQLiteConnection conn, string cmdText, SQLiteTransaction transaction)
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteDataSet(cmdText, null, CommandType.Text, transaction));
 }
Exemplo n.º 53
0
 private SQLiteCommand(string sqlText, SQLiteConnection dbConn, SQLiteTransaction trans)
 {
     sql         = sqlText;
     parent_conn = dbConn;
     transaction = trans;
 }
Exemplo n.º 54
0
 public void RollbackTransaction()
 {
     transaction_.Rollback();
     transaction_ = null;
 }
Exemplo n.º 55
0
        /// <summary>
        /// Removes a role from the data source for the configured applicationName.
        /// </summary>
        /// <param name="roleName">The name of the role to delete.</param>
        /// <param name="throwOnPopulatedRole">If true, throw an exception if <paramref name="roleName"/> has one or more members and do not delete <paramref name="roleName"/>.</param>
        /// <returns>
        /// true if the role was successfully deleted; otherwise, false.
        /// </returns>
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            if (!RoleExists(roleName))
            {
                throw new ProviderException("Role does not exist.");
            }

            if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0)
            {
                throw new ProviderException("Cannot delete a populated role.");
            }

            SQLiteTransaction tran = null;
            SQLiteConnection  cn   = GetDBConnectionForRole();

            try
            {
                if (cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                }

                if (!IsTransactionInProgress())
                {
                    tran = cn.BeginTransaction();
                }

                using (SQLiteCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM " + USERS_IN_ROLES_TB_NAME + " WHERE (RoleId IN"
                                      + " (SELECT RoleId FROM " + ROLE_TB_NAME + " WHERE LoweredRoleName = $RoleName))";

                    cmd.Parameters.AddWithValue("$RoleName", roleName.ToLowerInvariant());

                    cmd.ExecuteNonQuery();
                }

                using (SQLiteCommand cmd = cn.CreateCommand())
                {
                    cmd.CommandText = "DELETE FROM " + ROLE_TB_NAME + " WHERE LoweredRoleName = $RoleName AND ApplicationId = $ApplicationId";

                    cmd.Parameters.AddWithValue("$RoleName", roleName.ToLowerInvariant());
                    cmd.Parameters.AddWithValue("$ApplicationId", _applicationId);

                    cmd.ExecuteNonQuery();
                }

                // Commit the transaction if it's the one we created in this method.
                if (tran != null)
                {
                    tran.Commit();
                }
            }
            catch
            {
                if (tran != null)
                {
                    tran.Rollback();
                }

                throw;
            }
            finally
            {
                if (tran != null)
                {
                    tran.Dispose();
                }

                if (!IsTransactionInProgress())
                {
                    cn.Dispose();
                }
            }

            return(true);
        }
 /// <summary>
 /// Execute scalar as
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="commandType"></param>
 /// <param name="transaction"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T ExecuteScalarAs <T>(this SQLiteConnection conn, string cmdText, CommandType commandType, SQLiteTransaction transaction)
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteScalarAs <T>(cmdText, null, commandType, transaction));
 }
Exemplo n.º 57
0
 /// <summary>
 /// Execute Entities
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="parameters"></param>
 /// <param name="transaction"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static Task <IEnumerable <T> > ExecuteEntitiesAsync <T>(this SQLiteConnection conn, string cmdText, SQLiteParameter[] parameters, SQLiteTransaction transaction)
     where T : new()
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteEntitiesAsync <T>(cmdText, parameters, CommandType.Text, transaction));
 }
 /// <summary>
 /// Execute ExpandoObjects
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="cmdText"></param>
 /// <param name="transaction"></param>
 /// <returns></returns>
 public static Task <IEnumerable <dynamic> > ExecuteExpandoObjectsAsync(this SQLiteConnection conn, string cmdText, SQLiteTransaction transaction)
 {
     conn.CheckNull(nameof(conn));
     return(conn.ExecuteExpandoObjectsAsync(cmdText, null, CommandType.Text, transaction));
 }
Exemplo n.º 59
0
 internal bool IsOnlyTransaction(SQLiteTransaction transaction)
 {
     return(m_transactions.Count == 1 && m_transactions.Peek() == transaction);
 }
Exemplo n.º 60
0
        /// <summary>
        /// Create command
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="cmdText"></param>
        /// <param name="commandType"></param>
        /// <param name="transaction"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static SQLiteCommand CreateCommand(this SQLiteConnection conn,
                                                  string cmdText, CommandType commandType, SQLiteTransaction transaction,
                                                  params SQLiteParameter[] parameters)
        {
            conn.CheckNull(nameof(conn));

            var command = conn.CreateCommand();

            command.CommandText = cmdText;
            command.CommandType = commandType;
            command.Transaction = transaction;

            if (parameters is not null)
            {
                command.Parameters.AddRange(parameters);
            }

            return(command);
        }