static public bool execute(string sql)
        {
            PDO  pdo = new PDO();
            bool res = pdo.execute(sql);

            pdo.Dispose();
            return(res);
        }
        public Model findModel()
        {
            PDO       pdo       = new PDO();
            ResultSet resultSet = pdo.query(builder.buildSelect());

            _model.setAttr(resultSet);
            return(_model);
        }
        static public Hashtable find(string sql)
        {
            PDO       pdo       = new PDO();
            ResultSet resultSet = pdo.query(sql);
            Hashtable result    = resultSet.hasNext() ? resultSet.fetch() : new Hashtable();

            resultSet.Dispose();
            pdo.Dispose();
            return(result);
        }
        static public List <Hashtable> select(string sql)
        {
            List <Hashtable> list = new List <Hashtable>();
            PDO       pdo         = new PDO();
            ResultSet resultSet   = pdo.query(sql);

            while (resultSet.hasNext())
            {
                list.Add(resultSet.fetch());
            }
            resultSet.Dispose();
            pdo.Dispose();
            return(list);
        }
        public List <Hashtable> select()
        {
            List <Hashtable> result = new List <Hashtable>();
            string           sql    = builder.buildSelect();

            PDO       pdo       = new PDO();
            ResultSet resultSet = pdo.query(sql);

            while (resultSet.hasNext())
            {
                result.Add(resultSet.fetch());
            }
            resultSet.Dispose();
            pdo.Dispose();
            return(result);
        }
        public List <string> column(string field)
        {
            List <string> result = new List <string>();

            string sql = builder.buildSelect();

            PDO       pdo       = new PDO();
            ResultSet resultSet = pdo.query(sql);

            while (resultSet.hasNext())
            {
                Hashtable hashtable = resultSet.fetch();
                result.Add(hashtable[field].ToString());
            }
            resultSet.Dispose();
            pdo.Dispose();
            return(result);
        }
        protected void selectCollect(Collect <Hashtable> collect)
        {
            if (collect == null)
            {
                throw new NullReferenceException("collect 列不能为Null");
            }
            string sql = builder.buildSelect();

            PDO       pdo       = new PDO();
            ResultSet resultSet = pdo.query(sql);

            while (resultSet.hasNext())
            {
                collect.Add(resultSet.fetch());
            }
            resultSet.Dispose();
            pdo.Dispose();
        }
        public Hashtable column(string field, string key)
        {
            Hashtable result = new Hashtable();

            string sql = builder.buildSelect();

            PDO       pdo       = new PDO();
            ResultSet resultSet = pdo.query(sql);

            while (resultSet.hasNext())
            {
                Hashtable hashtable = resultSet.fetch();
                var       k         = hashtable[key];
                var       v         = hashtable[field];
                result[k] = v;
            }
            resultSet.Dispose();
            pdo.Dispose();
            return(result);
        }
        public Hashtable find()
        {
            //limit(1);
            string    sql       = builder.buildSelect();
            PDO       pdo       = new PDO();
            ResultSet resultSet = pdo.query(sql);
            Hashtable hashtable = null;

            if (resultSet.hasNext())
            {
                hashtable = resultSet.fetch();
            }
            else
            {
                hashtable = new Hashtable();
            }
            resultSet.Dispose();
            pdo.Dispose();
            return(hashtable);
        }
Beispiel #10
0
        public long executeInsert(string sql)
        {
            PDO  pdo    = new PDO();
            long lastID = -1;

            try
            {
                System.Diagnostics.Debug.WriteLine(sql);
                lastID = pdo.execute(sql, true);
            }
            catch (Exception e)
            {
                string message = e.Message;
                Console.WriteLine("SQL execute Error");
                Console.WriteLine("Message:" + message);
            }
            finally
            {
                pdo.Dispose();
            }
            return(lastID);
        }
        public bool executeUpdate(string sql)
        {
            bool res = false;
            PDO  pdo = new PDO();

            try
            {
                res = pdo.execute(sql);
            }
            catch (Exception e)
            {
                string message = e.Message;
                Console.WriteLine("SQL execute Error");
                Console.WriteLine("Message:" + message);
                //e.printStackTrace();
            }
            finally
            {
                pdo.Dispose();
            }

            return(res);
        }