示例#1
0
 public MySQLRow[] Select(
     string table,
     string[] cols          = null,
     MySQLData[] conditions = null,
     string sortBy          = null,
     MySQLSortOrder order   = MySQLSortOrder.None,
     int offset             = 0,
     int count = 0)
 {
     return(Select(
                table,
                cols,
                conditions != null ? conditions.Select(d => new MySQLCondition(d.Key, d.Value)).ToArray() : null,
                sortBy,
                order,
                offset,
                count));
 }
示例#2
0
        public MySQLRow[] Select(
            string table,
            string[] cols = null,
            MySQLCondition[] conditions = null,
            string sortBy        = null,
            MySQLSortOrder order = MySQLSortOrder.None,
            int offset           = 0,
            int count            = 0)
        {
            if (IsDisposed || !Connected || String.IsNullOrWhiteSpace(table))
            {
                return(new MySQLRow[0]);
            }

            var query = new StringBuilder();

            if (cols == null || cols.Length == 0)
            {
                cols = new[] { "*" };
            }

            if (cols.Length > 1)
            {
                query.AppendFormat("SELECT `{0}` FROM `{1}`", String.Join("`,`", cols), table);
            }
            else
            {
                query.AppendFormat("SELECT {0} FROM `{1}`", (cols[0] == "*" ? "*" : "`" + cols[0] + "`"), table);
            }

            AppendWhere(query, conditions);

            if (!String.IsNullOrWhiteSpace(sortBy) && order != MySQLSortOrder.None)
            {
                query.AppendFormat(" ORDER BY `{0}` {1}", sortBy, order);
            }

            if (count > 0 && offset >= 0)
            {
                query.AppendFormat(" LIMIT {0}, {1}", offset, count);
            }

            return(Query(query.ToString()) ?? new MySQLRow[0]);
        }