1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-08 03:22:21 +03:00

Towards getting ORDER BY to match against the correctin columns.

This version only looks at the left-most column in a compound SELECT.
That is the correct thing to do, but not what SQLite has historically done. (CVS 4620)

FossilOrigin-Name: bbddf16ac9539c7d48adfc73c5a90eecb8df6865
This commit is contained in:
drh
2007-12-13 02:45:31 +00:00
parent 9019f4a65f
commit 9a99334d54
5 changed files with 262 additions and 161 deletions

View File

@@ -74,6 +74,7 @@
#define etSRCLIST 14 /* a pointer to a SrcList */
#define etPOINTER 15 /* The %p conversion */
#define etSQLESCAPE3 16 /* %w -> Strings with '\"' doubled */
#define etORDINAL 17 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
/*
@@ -133,6 +134,7 @@ static const et_info fmtinfo[] = {
{ 'p', 16, 0, etPOINTER, 0, 1 },
{ 'T', 0, 2, etTOKEN, 0, 0 },
{ 'S', 0, 2, etSRCLIST, 0, 0 },
{ 'r', 10, 3, etORDINAL, 0, 0 },
};
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
@@ -384,6 +386,7 @@ static void vxprintf(
flag_longlong = sizeof(char*)==sizeof(i64);
flag_long = sizeof(char*)==sizeof(long int);
/* Fall through into the next case */
case etORDINAL:
case etRADIX:
if( infop->flags & FLAG_SIGNED ){
i64 v;
@@ -410,6 +413,9 @@ static void vxprintf(
precision = width-(prefix!=0);
}
bufpt = &buf[etBUFSIZE-1];
if( xtype==etORDINAL ){
bufpt -= 2;
}
{
register const char *cset; /* Use registers for speed */
register int base;
@@ -420,6 +426,13 @@ static void vxprintf(
longvalue = longvalue/base;
}while( longvalue>0 );
}
if( xtype==etORDINAL ){
static const char zOrd[] = "thstndrd";
int x = buf[etBUFSIZE-4] - '0';
if( x>=4 ) x = 0;
buf[etBUFSIZE-3] = zOrd[x*2];
buf[etBUFSIZE-2] = zOrd[x*2+1];
}
length = &buf[etBUFSIZE-1]-bufpt;
for(idx=precision-length; idx>0; idx--){
*(--bufpt) = '0'; /* Zero pad */