private bool ExecuteCreateTable(TestExecutePattern pattern, DataEngine db, string tableName, object controller)
        {
            int result          = 0;
            DbCommandBuilder cb = GetTableBuilder(tableName);

            Debug.WriteLine("");
            if (pattern == TestExecutePattern.InTransaction)
            {
                Debug.WriteLine("在事务中执行!");
                DBTransactionController trans = (DBTransactionController)controller;
                Debug.WriteLine(cb.Parsing(db.CommandParserAdapter));
                Debug.WriteLine("执行结果:");
                if (trans.DBA.TableExists(tableName))
                {
                    Debug.Write(string.Format("创建失败,表名 {0} 在数据库中已存在!", tableName));
                    return(false);
                }
                else
                {
                    result = trans.DBA.ExecuteNoneQuery(cb); // execute create table.
                    if (result != -1)
                    {
                        Debug.Write(string.Format("成功创建表 {0} !", tableName));
                        return(true);
                    }
                    else
                    {
                        Debug.Write(trans.DBA.Errors.LastOrDefault().Message);
                        return(false);
                    }
                }
            }
            else
            {
                Debug.WriteLine("批量处理器执行!");
                BatchCommander batch = (BatchCommander)controller;
                Debug.WriteLine(cb.Parsing(db.CommandParserAdapter));
                Debug.WriteLine("执行结果:");
                if (batch.TableExists(tableName))
                {
                    Debug.Write(string.Format("表名 {0} 在数据库中已存在!", tableName));
                    return(false);
                }
                else
                {
                    result = batch.ExecuteNonQuery(cb); // execute create table.
                    if (result != -1)
                    {
                        Debug.Write(string.Format("成功创建表 {0} !", tableName));
                        return(true);
                    }
                    else
                    {
                        Debug.Write(string.Format("表 {0} 创建失败!", tableName));
                        return(false);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 执行查询命令,返回查询结果中第一行第一列的值,并忽略所有其它的值.
        /// </summary>
        /// <param name="command">要执行的命令的构建器对象.</param>
        /// <returns>返回查询结果中第一行第一列的值,并忽略所有其它的值.</returns>
        public object QueryScalar(DbCommandBuilder command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (commander == null)
            {
                InitCommander();
            }
            else
            {
                commander.Parameters.Clear();
            }
            commander.CommandType = command.CommandType;
            commander.CommandText = command.Parsing(Engine.CommandParserAdapter);
            foreach (IDbDataParameter p in command.CommandParameters)
            {
                commander.Parameters.Add(p);
            }
            object result = commander.ExecuteScalar();

            return(result);
        }