int validate_typedata(struct query *, char *argv[], struct valobj *vo);
int validate_len(char *argv[], struct valobj *vo);
int validate_num(char *argv[], struct valobj *vo);
-int convert_wildcards_uppercase(char *arg);
extern SQLDA *sqlald(int, int, int);
SQLDA *mr_alloc_sqlda(void);
int validate_row(struct query *q, char *argv[], struct validate *v)
{
EXEC SQL BEGIN DECLARE SECTION;
- char qual[128];
int rowcount;
EXEC SQL END DECLARE SECTION;
+ char *qual;
/* build where clause */
- build_qual(v->qual, v->argc, argv, qual);
+ qual = build_qual(v->qual, v->argc, argv);
/* look for the record */
sprintf(stmt_buf, "SELECT COUNT (*) FROM %s WHERE %s",
table_name[q->rtable], qual);
dosql(sqlbuffer);
+ free(qual);
if (dbms_errno)
return mr_errcode;
case V_NUM:
status = validate_num(argv, vo);
break;
-
- case V_WILD:
- status = convert_wildcards(argv[vo->index]);
- break;
-
- case V_UPWILD:
- status = convert_wildcards_uppercase(argv[vo->index]);
- break;
-
}
if (status != MR_EXISTS)
namefield = vo->namefield;
idfield = vo->idfield;
- if ((tbl == USERS_TABLE && !strcmp(namefield, "login")) ||
- tbl == MACHINE_TABLE || tbl == SUBNET_TABLE || tbl == FILESYS_TABLE ||
- tbl == LIST_TABLE || tbl == CLUSTERS_TABLE || tbl == STRINGS_TABLE)
+ if (tbl == MACHINE_TABLE || tbl == SUBNET_TABLE)
{
- if (tbl == MACHINE_TABLE || tbl == SUBNET_TABLE)
- {
- for (c = name; *c; c++)
- {
- if (islower(*c))
- *c = toupper(*c);
- }
- }
- status = name_to_id(name, tbl, &id);
- if (status == 0)
- {
- *(int *)argv[vo->index] = id;
- return MR_EXISTS;
- }
- else if (status == MR_NO_MATCH && tbl == STRINGS_TABLE &&
- (q->type == APPEND || q->type == UPDATE))
+ for (c = name; *c; c++)
{
- id = add_string(name);
- cache_entry(name, STRINGS_TABLE, id);
- *(int *)argv[vo->index] = id;
- return MR_EXISTS;
+ if (islower(*c))
+ *c = toupper(*c);
}
- else if (status == MR_NO_MATCH || status == MR_NOT_UNIQUE)
- return vo->error;
- else
- return status;
}
- else
+ status = name_to_id(name, tbl, &id);
+ if (status == 0)
{
- /* else, it's `dubu', which uses unix_uid from users */
- EXEC SQL SELECT COUNT(*) INTO :rowcount FROM users
- WHERE unix_uid = :name;
- if (dbms_errno)
- return mr_errcode;
- if (rowcount != 1)
- return vo->error;
- EXEC SQL SELECT users_id INTO :id FROM users
- WHERE unix_uid = :name;
*(int *)argv[vo->index] = id;
return MR_EXISTS;
}
+ else if (status == MR_NO_MATCH && tbl == STRINGS_TABLE &&
+ (q->type == APPEND || q->type == UPDATE))
+ {
+ if (strlen(name) >= STRINGS_STRING_SIZE)
+ return MR_ARG_TOO_LONG;
+ id = add_string(name);
+ cache_entry(name, STRINGS_TABLE, id);
+ *(int *)argv[vo->index] = id;
+ return MR_EXISTS;
+ }
+ else if (status == MR_NO_MATCH || status == MR_NOT_UNIQUE)
+ return vo->error;
+ else
+ return status;
}
int validate_name(char *argv[], struct valobj *vo)
{
if (q->type != APPEND && q->type != UPDATE)
return MR_STRING;
+ if (strlen(name) >= STRINGS_STRING_SIZE)
+ return MR_ARG_TOO_LONG;
id = add_string(name);
cache_entry(name, STRINGS_TABLE, id);
}
if (*p == '-')
p++;
+ if (!*p)
+ return MR_INTEGER;
+
for (; *p; p++)
{
if (*p < '0' || *p > '9')
return it;
}
-
-/* Convert normal Unix-style wildcards to SQL voodoo */
-int convert_wildcards(char *arg)
-{
- static char buffer[ARGLEN];
- char *s, *d;
-
- for (d = buffer, s = arg; *s; s++)
- {
- switch (*s)
- {
- case '*':
- *d++ = '%';
- *d++ = '%';
- break;
- case '?':
- *d++ = '_';
- break;
- case '_':
- *d++ = '*';
- *d++ = *s;
- break;
- case '%':
- *d++ = '*';
- *d++ = '%';
- *d++ = '%';
- break;
- default:
- *d++ = *s;
- break;
- }
- }
- *d = '\0';
-
- /* Copy back into argv */
- strcpy(arg, buffer);
-
- return MR_EXISTS;
-}
-
-/* This version includes uppercase conversion, for things like gmac.
- * This is necessary because "LIKE" doesn't work with "uppercase()".
- * Including it in a wildcard routine saves making two passes over
- * the argument string.
- */
-int convert_wildcards_uppercase(char *arg)
-{
- static char buffer[ARGLEN];
- char *s, *d;
-
- for (d = buffer, s = arg; *s; s++)
- {
- switch (*s)
- {
- case '*':
- *d++ = '%';
- *d++ = '%';
- break;
- case '?':
- *d++ = '_';
- break;
- case '_':
- *d++ = '*';
- *d++ = *s;
- break;
- case '%':
- *d++ = '*';
- *d++ = '%';
- *d++ = '%';
- break;
- default:
- *d++ = toupper(*s); /* This is the only diff. */
- break;
- }
- }
- *d = '\0';
-
- /* Copy back into argv */
- strcpy(arg, buffer);
-
- return MR_EXISTS;
-}
-
-
/* Adds a string to the string table. Returns the id number.
*
*/