Example #1
0
        private void PrepareInsert(TableName tableName)
        {
            IList <DbField> fields = DbDefault.GetTableStructure(tableName).Columns;
            StringBuilder   sql    = new StringBuilder();

            sql.Append("INSERT INTO " + tableName.ToString() + "(");

            for (int j = 0; j < fields.Count; j++)
            {
                sql.Append(fields[j].FieldName + ", ");
            }

            sql = sql.Remove(sql.Length - 2, 1).Append(")");

            sql.Append(" VALUES(");

            for (int k = 0; k < fields.Count; k++)
            {
                sql.Append("?, ");
            }

            sql = sql.Remove(sql.Length - 2, 1).Append(")");

            Command.CommandType = CommandType.Text;
            Command.CommandText = sql.ToString();
            Command.Prepare();
        }
Example #2
0
        protected DataRow Select(TableName tableName, long identity)
        {
            String condition = String.Format("{0} = {1}",
                                             DbDefault.GetTableStructure(tableName).PKColumns[0], identity);

            return(Select(tableName, condition).Rows[0]);
        }
Example #3
0
        protected int[] Insert(TableName tableName, int numRows)
        {
            IList <DbField> fields = DbDefault.GetTableStructure(tableName).Columns;

            int[] result = new int[numRows];

            PrepareInsert(tableName);
            for (int i = 0; i < numRows; i++)
            {
                foreach (DbField field in fields)
                {
                    Command.Parameters.Add(
                        DbRandom.GetRandomFieldData(field));
                }

                Command.AddBatch();
            }

            return(Command.ExecuteBatch());
        }