コード例 #1
0
        /// <summary>
        /// Avoids the additional database trip that using SqliteCommandBuilder requires.
        /// </summary>
        /// <returns>The insert command.</returns>
        /// <param name="table">Table.</param>
        /// <param name="values">Values.</param>
        /// <param name="conflictResolutionStrategy">Conflict resolution strategy.</param>
        SqliteCommand GetInsertCommand(String table, ContentValues values, ConflictResolutionStrategy conflictResolutionStrategy)
        {
            var builder = new StringBuilder("INSERT");

            if (conflictResolutionStrategy != ConflictResolutionStrategy.None)
            {
                builder.Append(" OR ");
                builder.Append(conflictResolutionStrategy);
            }

            builder.Append(" INTO ");
            builder.Append(table);
            builder.Append(" (");

            // Append our content column names and create our SQL parameters.
            var valueSet     = values.ValueSet();
            var sqlParams    = new SqliteParameter[valueSet.LongCount()];
            var valueBuilder = new StringBuilder();
            var index        = 0L;

            foreach (var column in valueSet)
            {
                if (index > 0)
                {
                    builder.Append(",");
                    valueBuilder.Append(",");
                }

                builder.AppendFormat("{0}", column.Key);
                valueBuilder.AppendFormat("@{0}", column.Key);

                sqlParams[index++] = new SqliteParameter(column.Key, column.Value);
            }

            builder.Append(") VALUES (");
            builder.Append(valueBuilder);
            builder.Append(")");

            var sql     = builder.ToString();
            var command = new SqliteCommand(sql, Connection, currentTransaction);

            command.Parameters.Clear();
            command.Parameters.AddRange(sqlParams);

            return(command);
        }
コード例 #2
0
        /// <summary>
        /// Avoids the additional database trip that using SqliteCommandBuilder requires.
        /// </summary>
        /// <returns>The update command.</returns>
        /// <param name="table">Table.</param>
        /// <param name="values">Values.</param>
        /// <param name="whereClause">Where clause.</param>
        /// <param name="whereArgs">Where arguments.</param>
        SqliteCommand GetUpdateCommand(string table, ContentValues values, string whereClause, string[] whereArgs)
        {
            var builder = new StringBuilder("UPDATE ");

            builder.Append(table);
            builder.Append(" SET ");

            // Append our content column names and create our SQL parameters.
            var valueSet       = values.ValueSet();
            var valueSetLength = valueSet.Count();

            var whereArgsLength = (whereArgs != null ? whereArgs.Length : 0);
            var sqlParams       = new List <SqliteParameter>(valueSetLength + whereArgsLength);

            foreach (var column in valueSet)
            {
                if (sqlParams.Count > 0)
                {
                    builder.Append(",");
                }
                builder.AppendFormat("{0} = @{0}", column.Key);
                sqlParams.Add(new SqliteParameter(column.Key, column.Value));
            }

            if (!whereClause.IsEmpty())
            {
                builder.Append(" WHERE ");
                builder.Append(whereClause.ReplacePositionalParams());
            }

            if (whereArgsLength > 0)
            {
                sqlParams.AddRange(whereArgs.ToSqliteParameters());
            }

            var sql     = builder.ToString();
            var command = new SqliteCommand(sql, Connection, currentTransaction);

            command.Parameters.Clear();
            command.Parameters.AddRange(sqlParams.ToArray());

            return(command);
        }
コード例 #3
0
        /// <summary>
        /// Avoids the additional database trip that using SqliteCommandBuilder requires.
        /// </summary>
        /// <returns>The insert command.</returns>
        /// <param name="table">Table.</param>
        /// <param name="values">Values.</param>
        /// <param name="conflictResolutionStrategy">Conflict resolution strategy.</param>
        SqliteCommand GetInsertCommand (String table, ContentValues values, ConflictResolutionStrategy conflictResolutionStrategy)
        {
            var builder = new StringBuilder("INSERT");

            if (conflictResolutionStrategy != ConflictResolutionStrategy.None) {
                builder.Append(" OR ");
                builder.Append(conflictResolutionStrategy);
            }

            builder.Append(" INTO ");
            builder.Append(table);
            builder.Append(" (");

            // Append our content column names and create our SQL parameters.
            var valueSet = values.ValueSet();
            var sqlParams = new SqliteParameter[valueSet.LongCount()];
            var valueBuilder = new StringBuilder();
            var index = 0L;

            foreach(var column in valueSet)
            {
                if (index > 0) {
                         builder.Append(",");
                    valueBuilder.Append(",");
                }

                     builder.AppendFormat( "{0}", column.Key);
                valueBuilder.AppendFormat("@{0}", column.Key);

                sqlParams[index++] = new SqliteParameter(column.Key, column.Value);
            }

            builder.Append(") VALUES (");
            builder.Append(valueBuilder);
            builder.Append(")");

            var sql = builder.ToString();
            var command = new SqliteCommand(sql, Connection, currentTransaction);
            command.Parameters.Clear();
            command.Parameters.AddRange(sqlParams);

            return command;
        }
コード例 #4
0
        /// <summary>
        /// Avoids the additional database trip that using SqliteCommandBuilder requires.
        /// </summary>
        /// <returns>The update command.</returns>
        /// <param name="table">Table.</param>
        /// <param name="values">Values.</param>
        /// <param name="whereClause">Where clause.</param>
        /// <param name="whereArgs">Where arguments.</param>
        SqliteCommand GetUpdateCommand (string table, ContentValues values, string whereClause, string[] whereArgs)
        {
            var builder = new StringBuilder("UPDATE ");

            builder.Append(table);
            builder.Append(" SET ");

            // Append our content column names and create our SQL parameters.
            var valueSet = values.ValueSet();
            var valueSetLength = valueSet.Count();

            var whereArgsLength = (whereArgs != null ? whereArgs.Length : 0);
            var sqlParams = new List<SqliteParameter>(valueSetLength + whereArgsLength);

            foreach(var column in valueSet)
            {
                if (sqlParams.Count > 0) {
                    builder.Append(",");
                }
                builder.AppendFormat( "{0} = @{0}", column.Key);
                sqlParams.Add(new SqliteParameter(column.Key, column.Value));
            }

            if (!whereClause.IsEmpty()) {
                builder.Append(" WHERE ");
                builder.Append(whereClause.ReplacePositionalParams());
            }

            if (whereArgsLength > 0)
                sqlParams.AddRange(whereArgs.ToSqliteParameters());

            var sql = builder.ToString();
            var command = new SqliteCommand(sql, Connection, currentTransaction);
            command.Parameters.Clear();
            command.Parameters.AddRange(sqlParams.ToArray());

            return command;
        }
コード例 #5
0
		/// <summary>
		/// Avoids the additional database trip that using SqliteCommandBuilder requires.
		/// </summary>
		/// <returns>The insert command.</returns>
		/// <param name="table">Table.</param>
		/// <param name="values">Values.</param>
		/// <param name="conflictResolutionStrategy">Conflict resolution strategy.</param>
		ISQLiteStatement GetInsertCommand (String table, ContentValues values, ConflictResolutionStrategy conflictResolutionStrategy)
		{
			var builder = new StringBuilder("INSERT");

			if (conflictResolutionStrategy != ConflictResolutionStrategy.None) {
				builder.Append(" OR ");
				builder.Append(conflictResolutionStrategy);
			}

			builder.Append(" INTO ");
			builder.Append(table);
			builder.Append(" (");

			// Append our content column names and create our SQL parameters.
			var valueSet = values.ValueSet();
			var sqlParams = new Dictionary<string, object> (); 
			var valueBuilder = new StringBuilder();
			var index = 0L;

			foreach(var column in valueSet)
			{
				if (index > 0) {
					builder.Append(",");
					valueBuilder.Append(",");
				}

				builder.AppendFormat( "{0}", column.Key);
				valueBuilder.AppendFormat("@{0}", column.Key);

				index++;
				sqlParams.Add (column.Key, column.Value);
			}

			builder.Append(") VALUES (");
			builder.Append(valueBuilder);
			builder.Append(")");

			var stmt = connection.Prepare (builder.ToString ());
			foreach (var p in sqlParams)
				stmt.Bind (p.Key, p.Value);

			return stmt;
		}
コード例 #6
0
		/// <summary>
		/// Avoids the additional database trip that using SqliteCommandBuilder requires.
		/// </summary>
		/// <returns>The update command.</returns>
		/// <param name="table">Table.</param>
		/// <param name="values">Values.</param>
		/// <param name="whereClause">Where clause.</param>
		/// <param name="whereArgs">Where arguments.</param>
		ISQLiteStatement GetUpdateCommand (string table, ContentValues values, string whereClause, string[] whereArgs)
		{
			var builder = new StringBuilder("UPDATE ");

			builder.Append(table);
			builder.Append(" SET ");

			// Append our content column names and create our SQL parameters.
			var valueSet = values.ValueSet();
			var valueSetLength = valueSet.Count();

			var whereArgsLength = (whereArgs != null ? whereArgs.Length : 0);
			var sqlParams = new Dictionary<string, object>(valueSetLength + whereArgsLength);

			foreach(var column in valueSet)
			{
				if (sqlParams.Count > 0) {
					builder.Append(",");
				}
				builder.AppendFormat( "{0} = @{0}", column.Key);
				sqlParams.Add(column.Key, column.Value);
			}
				
			if (!whereClause.IsEmpty()) {
				builder.Append(" WHERE ");
				builder.Append(whereClause.ReplacePositionalParams());
			}

			if (whereArgsLength > 0) {
				for (int i = 0; i < whereArgs.Length; i++)
					sqlParams.Add ("@" + i, whereArgs [i]);
			}

			var sql = builder.ToString();
			var stmt = connection.Prepare (sql);
			foreach (var p in sqlParams)
				stmt.Bind (p.Key, p.Value);

			return stmt;
		}
        /// <summary>
        /// Avoids the additional database trip that using SqliteCommandBuilder requires.
        /// </summary>
        /// <returns>The insert command.</returns>
        /// <param name="table">Table.</param>
        /// <param name="values">Values.</param>
        /// <param name="conflictResolutionStrategy">Conflict resolution strategy.</param>
        sqlite3_stmt GetInsertCommand (String table, ContentValues values, ConflictResolutionStrategy conflictResolutionStrategy)
        {
            var builder = new StringBuilder("INSERT");

            if (conflictResolutionStrategy != ConflictResolutionStrategy.None) {
                builder.Append(" OR ");
                builder.Append(conflictResolutionStrategy);
            }

            builder.Append(" INTO ");
            builder.Append(table);
            builder.Append(" (");

            // Append our content column names and create our SQL parameters.
            var valueSet = values.ValueSet();
            var valueBuilder = new StringBuilder();
            var index = 0;

            foreach(var column in valueSet)
            {
                if (index > 0) {
                    builder.Append(",");
                    valueBuilder.Append(",");
                }

                builder.AppendFormat( "{0}", column.Key);
                valueBuilder.Append("@");
                index++;
            }

            builder.Append(") VALUES (");
            builder.Append(valueBuilder);
            builder.Append(")");

            var sql = builder.ToString();
            var command = Connection.Prepare(sql);

            index = 1;
            foreach(var val in valueSet)
            {
                var key = val.Key;
                command.Bind(index++, values[key]);
            }

            return command;
        }
        /// <summary>
        /// Avoids the additional database trip that using SqliteCommandBuilder requires.
        /// </summary>
        /// <returns>The update command.</returns>
        /// <param name="table">Table.</param>
        /// <param name="values">Values.</param>
        /// <param name="whereClause">Where clause.</param>
        /// <param name="whereArgs">Where arguments.</param>
        sqlite3_stmt GetUpdateCommand (string table, ContentValues values, string whereClause, string[] whereArgs)
        {
            var builder = new StringBuilder("UPDATE ");

            builder.Append(table);
            builder.Append(" SET ");

            // Append our content column names and create our SQL parameters.
            var valueSet = values.ValueSet();
            var valueSetLength = valueSet.Count();

            var whereArgsLength = (whereArgs != null ? whereArgs.Length : 0);

            var index = 0;
            foreach(var column in valueSet)
            {
                if (index++ > 0) {
                    builder.Append(",");
                }
                builder.AppendFormat("{0} = @", column.Key);
            }

            if (!String.IsNullOrWhiteSpace(whereClause)) {
                builder.Append(" WHERE ");
                builder.Append(whereClause);
            }

            var sql = builder.ToString();
            var command = Connection.Prepare(sql);
            for(var i = 1; i <= whereArgs.Length; i++)
            {
                command.Bind(i, whereArgs[i - 1]);
            }
            return command;
        }