public void CreateParameter_works() { using (var command = new SQLiteCommand()) { Assert.NotNull(command.CreateParameter()); } }
public void Connection_validates_value() { using (var command = new SQLiteCommand()) { Assert.Throws<ArgumentNullException>("value", () => command.Connection = null); } }
public void CommandType_text_by_default() { using (var command = new SQLiteCommand()) { Assert.Equal(CommandType.Text, command.CommandType); } }
public void CommandText_validates_value() { using (var command = new SQLiteCommand()) { var ex = Assert.Throws<ArgumentException>(() => command.CommandText = null); Assert.Equal(Strings.FormatArgumentIsNullOrWhitespace("value"), ex.Message); } }
public void CommandType_validates_value() { using (var command = new SQLiteCommand()) { var ex = Assert.Throws<ArgumentException>(() => command.CommandType = 0); Assert.Equal(Strings.FormatInvalidCommandType(0), ex.Message); } }
public void Parameters_works() { using (var command = new SQLiteCommand()) { var result = command.Parameters; Assert.NotNull(result); Assert.Same(result, command.Parameters); } }
private static void AttachParameters(SQLiteCommand command, DbParameter[] commandParameters) { if (command == null) throw new ArgumentNullException("command"); if (commandParameters != null) { foreach (DbParameter p in commandParameters) { if (p != null) { if ((p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input) && (p.Value == null)) { p.Value = DBNull.Value; } command.Parameters.Add(p); } } } }
private static void PrepareCommand( SQLiteCommand command, SQLiteConnection connection, SQLiteTransaction transaction, CommandType commandType, string commandText, DbParameter[] commandParameters) { if (command == null) throw new ArgumentNullException("command"); if (string.IsNullOrEmpty(commandText)) throw new ArgumentNullException("commandText"); command.CommandType = commandType; command.CommandText = commandText; command.Connection = connection; 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; } if (commandParameters != null) { AttachParameters(command, commandParameters); } }
private static SQLiteDataReader CreateReader() { var command = new SQLiteCommand(); var reader = new SQLiteDataReader(command, new StatementHandle[0], 0); command.OpenReader = reader; return reader; }
public static int ExecuteNonQuery(SQLiteConnection connection, string commandText, params DbParameter[] parameters) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = connection; cmd.CommandText = commandText; cmd.CommandType = CommandType.Text; if (parameters != null) { foreach (DbParameter p in parameters) { cmd.Parameters.Add(p); } } return cmd.ExecuteNonQuery(); } }
public void Cancel_not_supported() { using (var command = new SQLiteCommand()) { Assert.Throws<NotSupportedException>(() => command.Cancel()); } }
public void ExecuteReader_throws_when_no_connection() { using (var command = new SQLiteCommand()) { var ex = Assert.Throws<InvalidOperationException>(() => command.ExecuteReader()); Assert.Equal(Strings.FormatCallRequiresOpenConnection("ExecuteReader"), ex.Message); } }
public void ExecuteNonQuery_can_be_called_more_than_once_when_connection_changed() { using (var command = new SQLiteCommand("SELECT 1")) { using (var connection = new SQLiteConnection("Filename=:memory:")) { command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); } using (var connection = new SQLiteConnection("Filename=:memory:")) { command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); } } }