示例#1
0
文件: SqlBox.cs 项目: built/BoxBoy
        public bool createStream(Item item)
        {
            SqlBoxQuery query = new SqlBoxQuery();

            if (item.UsesAutoId)
            {
                query.Append("CREATE TABLE %table%(%pk% int IDENTITY(1,1) PRIMARY KEY CLUSTERED%fields%)");
            }
            else
            {
                query.Append("CREATE TABLE %table%(%pk% int PRIMARY KEY CLUSTERED%fields%)");
            }
            string       val    = ", %name% varchar(255) DEFAULT NULL";
            string       strA   = item.getIdField();
            StringTheory theory = new StringTheory();

            foreach (string str3 in item.getBoxView().Keys)
            {
                if (string.Compare(strA, str3, true) != 0)
                {
                    theory.Append(val);
                    theory.Replace("%name%", str3);
                }
            }
            query.Replace("%table%", item.getStreamName());
            query.Replace("%pk%", strA);
            query.Replace("%fields%", theory);
            Console.WriteLine(query);
            this.SqlDatabase.process(query);
            return(this.streamExists(item));
        }
示例#2
0
        public int process(SqlBoxQuery query, ArrayList results)
        {
            int count = -1;

            if (!query.IsEmpty())
            {
                this.m_lastQuery = query.ToString();
                if (this.DbConnection == null)
                {
                    return(count);
                }
                try
                {
                    OleDbCommand command = this.DbConnection.CreateCommand();
                    command.CommandText = query.ToString();
                    OleDbDataReader resultSet = command.ExecuteReader();
                    this.CollectResultsInList(results, resultSet);
                    count = results.Count;
                    resultSet.Close();
                }
                catch (Exception exception)
                {
                    this.error.message = "An error occurred while processing a query.";
                    this.error.info    = exception.ToString();
                }
            }
            return(count);
        }
示例#3
0
        public int process(SqlBoxQuery query)
        {
            int num = -1;

            if (!query.IsEmpty())
            {
                this.m_lastQuery = query.ToString();
                if ((this.DbConnection == null) || (this.DbConnection.State != System.Data.ConnectionState.Open))
                {
                    return(num);
                }
                try
                {
                    OleDbCommand command = this.DbConnection.CreateCommand();
                    command.CommandText = query.ToString();
                    num = command.ExecuteNonQuery();
                }
                catch (Exception exception)
                {
                    this.error.message = "An error occurred while processing a query.";
                    this.error.info    = exception.ToString();
                }
            }
            return(num);
        }
示例#4
0
文件: SqlBox.cs 项目: built/BoxBoy
        public bool deleteStream(Item item)
        {
            SqlBoxQuery query = new SqlBoxQuery();

            query.Append("drop table " + item.getStreamName());
            this.SqlDatabase.process(query);
            return(!this.streamExists(item));
        }
示例#5
0
文件: SqlBox.cs 项目: built/BoxBoy
        public bool streamExists(string streamName)
        {
            ArrayList   results = new ArrayList();
            SqlBoxQuery query   = new SqlBoxQuery();

            query.Append("SELECT * FROM information_schema.tables WHERE TABLE_NAME = '%StreamName%'");
            query.Replace("%StreamName%", streamName);
            this.SqlDatabase.process(query, results);
            return(results.Count > 0);
        }