/ Check-in [c6a85c8e]
Login
Overview
Comment:Added IFNULL and NVL functions. (CVS 401)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c6a85c8ee3d653a294bcc033ac6cab2b6de06f96
User & Date: drh 2002-02-28 00:46:26
Context
2002-02-28
01:46
Fix the coredump. There are still problems in the test suite though. (CVS 402) check-in: 6af10cc5 user: drh tags: trunk
00:46
Added IFNULL and NVL functions. (CVS 401) check-in: c6a85c8e user: drh tags: trunk
00:41
Completely remove the old SQL function system and replace it with the new user functions. The code currently compiles but it coredumps on the test suite. Do not use in its present state. (CVS 400) check-in: 50797fee user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/func.c.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
160
161
162
163
164
165
166












167
168
169
170
171
172
173
...
346
347
348
349
350
351
352


353
354
355
356
357
358
359
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.6 2002/02/28 00:41:10 drh Exp $
*/
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include "sqliteInt.h"

................................................................................
  if( argc<1 || argv[0]==0 ) return;
  z = sqlite_set_result_string(context, argv[0], -1);
  if( z==0 ) return;
  for(i=0; z[i]; i++){
    if( isupper(z[i]) ) z[i] = tolower(z[i]);
  }
}













/*
** An instance of the following structure holds the context of a
** sum() or avg() aggregate computation.
*/
typedef struct SumCtx SumCtx;
struct SumCtx {
................................................................................
    { "length", 1, lengthFunc },
    { "substr", 3, substrFunc },
    { "abs",    1, absFunc    },
    { "round",  1, roundFunc  },
    { "round",  2, roundFunc  },
    { "upper",  1, upperFunc  },
    { "lower",  1, lowerFunc  },


  };
  static struct {
    char *zName;
    int nArg;
    void (*xStep)(sqlite_func*,int,const char**);
    void (*xFinalize)(sqlite_func*);
  } aAggs[] = {







|







 







>
>
>
>
>
>
>
>
>
>
>
>







 







>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.7 2002/02/28 00:46:26 drh Exp $
*/
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include "sqliteInt.h"

................................................................................
  if( argc<1 || argv[0]==0 ) return;
  z = sqlite_set_result_string(context, argv[0], -1);
  if( z==0 ) return;
  for(i=0; z[i]; i++){
    if( isupper(z[i]) ) z[i] = tolower(z[i]);
  }
}

/*
** Implementation of the IFNULL() and NVL() functions.  (both do the
** same thing.  They return their first argument if it is not NULL or
** their second argument if the first is NULL.
*/
static void ifnullFunc(sqlite_func *context, int argc, const char **argv){
  const char *z;
  assert( argc==2 );
  z = argv[0] ? argv[0] : argv[1];
  sqlite_set_result_string(context, z, -1);
}

/*
** An instance of the following structure holds the context of a
** sum() or avg() aggregate computation.
*/
typedef struct SumCtx SumCtx;
struct SumCtx {
................................................................................
    { "length", 1, lengthFunc },
    { "substr", 3, substrFunc },
    { "abs",    1, absFunc    },
    { "round",  1, roundFunc  },
    { "round",  2, roundFunc  },
    { "upper",  1, upperFunc  },
    { "lower",  1, lowerFunc  },
    { "ifnull", 2, ifnullFunc },
    { "nvl",    2, ifnullFunc },
  };
  static struct {
    char *zName;
    int nArg;
    void (*xStep)(sqlite_func*,int,const char**);
    void (*xFinalize)(sqlite_func*);
  } aAggs[] = {