Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv26186/server
Modified Files:
sql_select.mx
Log Message:
added support for order by on 'very simple' column expressions.
Index: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.190
retrieving revision 1.191
diff -u -d -r1.190 -r1.191
--- sql_select.mx 23 May 2007 22:05:59 -0000 1.190
+++ sql_select.mx 29 May 2007 21:32:13 -0000 1.191
@@ -1350,7 +1350,8 @@
As SQL-3 dropped support for order by number (column position in result
table) so we also do not support it. Unfortunately SQL-3 added new crap,
order by 'expression', where expression should match a result column
- expression. We also do not support this (just use as bla and order by bla!).
+ expression. We only support single column name expressions
+ (else just use as bla and order by bla!).
SQL-3 supports ordering on columns not in the result table,
we do support that if the column is a direct base column.
*/
@@ -1402,6 +1403,64 @@
return sql_error(sql, 02, "ORDER BY: absolute column names not
supported");
}
+
+/* find selection expressions matching the order by column expression */
+
+/* first limit to simple columns only */
+static stmt *
+orderby_column_exp(mvc *sql, symbol *column_r, stmt *s)
+{
+ dlist *l = column_r->data.lval;
+
+ assert(column_r->token == SQL_COLUMN && column_r->type == type_list);
+
+ if (dlist_length(l) == 1) {
+ char *name = l->h->data.sval;
+ node *n;
+
+ for (n = s->op1.lval->h; n; n = n->next) {
+ stmt *t = n->data;
+
+ if (t->type == st_alias) {
+ char *cn = column_name(t->op1.stval);
+
+ if (strcmp(cn, name) == 0) {
+ _DELETE(cn);
+ return stmt_dup(t);
+ }
+ _DELETE(cn);
+ }
+ }
+ return sql_error(sql, 02, "ORDER BY: no such column '%s'",
name);
+ }
+ if (dlist_length(l) == 2) {
+ char *tname = l->h->data.sval;
+ char *name = l->h->next->data.sval;
+ node *n;
+
+ for (n = s->op1.lval->h; n; n = n->next) {
+ stmt *t = n->data;
+
+ if (t->type == st_alias) {
+ char *tn = table_name(t->op1.stval);
+ char *cn = column_name(t->op1.stval);
+
+ if (tn && strcmp(tn, tname) == 0 && strcmp(cn,
name) == 0) {
+ if (tn)
+ _DELETE(tn);
+ _DELETE(cn);
+ return stmt_dup(t);
+ }
+ if (tn)
+ _DELETE(tn);
+ _DELETE(cn);
+ }
+ }
+ return sql_error(sql, 02, "ORDER BY: no such column '%s'",
name);
+ }
+ return sql_error(sql, 02, "ORDER BY: absolute column names not
supported");
+}
+
static stmt *
query_orderby(mvc *sql, scope *scp, symbol *orderby, stmt *sel, stmt *subset,
group *grp)
{
@@ -1421,6 +1480,13 @@
if (sel)
sc = orderby_column_ref(sql, col, sel);
+ if (sel && !sc) {
+ /* reset error */
+ sql->errstr[0] = '\0';
+ sql->session->status = 0;
+
+ sc = orderby_column_exp(sql, col, sel);
+ }
/* fall back to column references, ie those not in
the selection result */
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins