public void Test007() { SqlTableRef orders = SqlDml.TableRef(schema.Tables["invoice"]); SqlSelect select = SqlDml.Select(orders); select.Limit = 10; select.Columns.Add(SqlDml.Asterisk); sqlCommand.CommandText = Compile(select).GetCommandText(); sqlCommand.Prepare(); DbCommandExecutionResult r = GetExecuteDataReaderResult(sqlCommand); Assert.AreEqual(10, r.RowCount); }
public void Test006() { SqlTableRef orders = SqlDml.TableRef(schema.Tables["invoice"]); SqlSelect select = SqlDml.Select(orders); select.Columns.Add(SqlDml.Asterisk); select.Where = orders["PaymentDate"] > new DateTime(2013, 8, 1); select.OrderBy.Add(orders["PaymentDate"], false); sqlCommand.CommandText = Compile(select).GetCommandText(); sqlCommand.Prepare(); DbCommandExecutionResult r = GetExecuteDataReaderResult(sqlCommand); Assert.AreEqual(14, r.RowCount); }
public void Test006() { SqlTableRef payment = SqlDml.TableRef(schema.Tables["payment"]); SqlSelect select = SqlDml.Select(payment); select.Columns.Add(SqlDml.Asterisk); select.Where = payment["payment_date"] > DateTime.Now; select.OrderBy.Add(payment["payment_date"], false); sqlCommand.CommandText = Compile(select).GetCommandText(); sqlCommand.Prepare(); DbCommandExecutionResult r = GetExecuteDataReaderResult(sqlCommand); Assert.AreEqual(r.RowCount, 0); }
protected static DbCommandExecutionResult GetExecuteNonQueryResult(IDbCommand cmd) { DbCommandExecutionResult result = new DbCommandExecutionResult(); try { cmd.Transaction = cmd.Connection.BeginTransaction(); result.RowCount = cmd.ExecuteNonQuery(); } // catch (Exception e) { // Console.WriteLine(e); // } finally { cmd.Transaction.Rollback(); } return(result); }
private static DbCommandExecutionResult GetExecuteDataReaderResult(IDbCommand cmd) { DbCommandExecutionResult result = new DbCommandExecutionResult(); try { cmd.Transaction = cmd.Connection.BeginTransaction(); int rowCount = 0; int fieldCount = 0; string[] fieldNames = new string[0]; using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (rowCount == 0) { fieldCount = reader.FieldCount; fieldNames = new string[fieldCount]; for (int i = 0; i < fieldCount; i++) { fieldNames[i] = reader.GetName(i); } } rowCount++; } } result.RowCount = rowCount; result.FieldCount = fieldCount; result.FieldNames = fieldNames; } // catch (Exception e) { // Console.WriteLine(e); // } finally { cmd.Transaction.Rollback(); } return(result); }