2003-08-13 03:27:48 +02:00
|
|
|
%{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2004-03-19 02:16:36 +01:00
|
|
|
* Copyright 2002-2004 Mike McCormack for CodeWeavers
|
2003-08-13 03:27:48 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-13 03:27:48 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-08-13 03:27:48 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "query.h"
|
2005-05-23 14:08:17 +02:00
|
|
|
#include "wine/list.h"
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2009-02-26 04:43:54 +01:00
|
|
|
static UINT SQL_getstring( void *info, const struct sql_str *strdata, LPWSTR *str );
|
2005-05-23 14:08:17 +02:00
|
|
|
static INT SQL_getint( void *info );
|
2006-09-11 21:53:04 +02:00
|
|
|
static int sql_lex( void *SQL_lval, SQL_input *info );
|
2013-08-01 12:00:04 +02:00
|
|
|
static int sql_error( SQL_input *info, const char *str);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-05-28 15:03:49 +02:00
|
|
|
static LPWSTR parser_add_table( void *info, LPCWSTR list, LPCWSTR table );
|
2005-05-23 14:08:17 +02:00
|
|
|
static void *parser_alloc( void *info, unsigned int sz );
|
2005-05-29 22:17:16 +02:00
|
|
|
static column_info *parser_alloc_column( void *info, LPCWSTR table, LPCWSTR column );
|
2004-03-16 20:18:22 +01:00
|
|
|
|
2009-03-02 06:41:30 +01:00
|
|
|
static BOOL SQL_MarkPrimaryKeys( column_info **cols, column_info *keys);
|
2005-05-23 14:08:17 +02:00
|
|
|
|
|
|
|
static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct expr *r );
|
2006-11-07 07:07:16 +01:00
|
|
|
static struct expr * EXPR_unary( void *info, struct expr *l, UINT op );
|
2007-06-12 22:51:36 +02:00
|
|
|
static struct expr * EXPR_column( void *info, const column_info *column );
|
2005-05-31 11:30:01 +02:00
|
|
|
static struct expr * EXPR_ival( void *info, int val );
|
2007-06-16 19:05:32 +02:00
|
|
|
static struct expr * EXPR_sval( void *info, const struct sql_str *str );
|
2005-05-23 14:08:17 +02:00
|
|
|
static struct expr * EXPR_wildcard( void *info );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-12-16 03:18:31 +01:00
|
|
|
#define PARSER_BUBBLE_UP_VIEW( sql, result, current_view ) \
|
|
|
|
*sql->view = current_view; \
|
|
|
|
result = current_view
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
%}
|
|
|
|
|
2013-08-01 12:00:04 +02:00
|
|
|
%lex-param { SQL_input *info }
|
|
|
|
%parse-param { SQL_input *info }
|
2022-01-21 12:50:25 +01:00
|
|
|
%define api.prefix {sql_}
|
2019-11-25 14:37:05 +01:00
|
|
|
%define api.pure
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
%union
|
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
struct sql_str str;
|
2003-08-13 03:27:48 +02:00
|
|
|
LPWSTR string;
|
2005-05-29 22:17:16 +02:00
|
|
|
column_info *column_list;
|
2004-03-16 20:18:22 +01:00
|
|
|
MSIVIEW *query;
|
2003-08-13 03:27:48 +02:00
|
|
|
struct expr *expr;
|
2004-03-16 20:18:22 +01:00
|
|
|
USHORT column_type;
|
2005-05-31 11:30:01 +02:00
|
|
|
int integer;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-02 22:56:54 +02:00
|
|
|
%token TK_ALTER TK_AND TK_BY TK_CHAR TK_COMMA TK_CREATE TK_DELETE TK_DROP
|
2007-07-20 23:01:13 +02:00
|
|
|
%token TK_DISTINCT TK_DOT TK_EQ TK_FREE TK_FROM TK_GE TK_GT TK_HOLD TK_ADD
|
2006-10-31 06:34:07 +01:00
|
|
|
%token <str> TK_ID
|
|
|
|
%token TK_ILLEGAL TK_INSERT TK_INT
|
2004-06-26 02:11:08 +02:00
|
|
|
%token <str> TK_INTEGER
|
2006-10-31 06:34:07 +01:00
|
|
|
%token TK_INTO TK_IS TK_KEY TK_LE TK_LONG TK_LONGCHAR TK_LP TK_LT
|
|
|
|
%token TK_LOCALIZABLE TK_MINUS TK_NE TK_NOT TK_NULL
|
|
|
|
%token TK_OBJECT TK_OR TK_ORDER TK_PRIMARY TK_RP
|
|
|
|
%token TK_SELECT TK_SET TK_SHORT TK_SPACE TK_STAR
|
2004-06-26 02:11:08 +02:00
|
|
|
%token <str> TK_STRING
|
2006-10-31 06:34:07 +01:00
|
|
|
%token TK_TABLE TK_TEMPORARY TK_UPDATE TK_VALUES TK_WHERE TK_WILDCARD
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2003-09-08 21:38:45 +02:00
|
|
|
/*
|
|
|
|
* These are extra tokens used by the lexer but never seen by the
|
|
|
|
* parser. We put them in a rule so that the parser generator will
|
|
|
|
* add them to the parse.h output file.
|
|
|
|
*
|
|
|
|
*/
|
2003-08-13 03:27:48 +02:00
|
|
|
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
|
|
|
|
COLUMN AGG_FUNCTION.
|
|
|
|
|
2011-12-23 13:54:26 +01:00
|
|
|
%type <string> table tablelist id string
|
|
|
|
%type <column_list> selcollist collist selcolumn column column_and_type column_def table_def
|
2005-05-30 13:32:18 +02:00
|
|
|
%type <column_list> column_assignment update_assign_list constlist
|
2011-10-20 14:22:25 +02:00
|
|
|
%type <query> query from selectfrom unorderdfrom
|
2008-10-02 22:56:54 +02:00
|
|
|
%type <query> oneupdate onedelete oneselect onequery onecreate oneinsert onealter onedrop
|
2004-03-20 20:18:46 +01:00
|
|
|
%type <expr> expr val column_val const_val
|
2004-03-19 02:16:36 +01:00
|
|
|
%type <column_type> column_type data_type data_type_l data_count
|
2006-08-18 07:09:03 +02:00
|
|
|
%type <integer> number alterop
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2006-02-07 16:24:51 +01:00
|
|
|
%left TK_OR
|
|
|
|
%left TK_AND
|
|
|
|
%left TK_NOT
|
2006-10-31 06:34:07 +01:00
|
|
|
%left TK_EQ TK_NE TK_LT TK_GT TK_LE TK_GE TK_LIKE
|
2006-02-07 16:24:51 +01:00
|
|
|
%right TK_NEGATION
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
%%
|
|
|
|
|
2005-05-23 11:53:43 +02:00
|
|
|
query:
|
|
|
|
onequery
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
*sql->view = $1;
|
|
|
|
}
|
2005-05-23 11:53:43 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
onequery:
|
|
|
|
oneselect
|
2004-03-16 20:18:22 +01:00
|
|
|
| onecreate
|
2004-03-20 20:18:46 +01:00
|
|
|
| oneinsert
|
2004-07-04 02:30:02 +02:00
|
|
|
| oneupdate
|
2005-02-14 12:07:13 +01:00
|
|
|
| onedelete
|
2006-08-18 07:09:03 +02:00
|
|
|
| onealter
|
2008-10-02 22:56:54 +02:00
|
|
|
| onedrop
|
2004-03-20 20:18:46 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
oneinsert:
|
2011-12-23 13:54:26 +01:00
|
|
|
TK_INSERT TK_INTO table TK_LP collist TK_RP TK_VALUES TK_LP constlist TK_RP
|
2005-05-23 18:23:11 +02:00
|
|
|
{
|
|
|
|
SQL_input *sql = (SQL_input*) info;
|
2006-10-31 06:34:07 +01:00
|
|
|
MSIVIEW *insert = NULL;
|
2004-03-20 20:18:46 +01:00
|
|
|
|
2008-04-21 23:23:21 +02:00
|
|
|
INSERT_CreateView( sql->db, &insert, $3, $5, $9, FALSE );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !insert )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, insert );
|
2005-05-23 18:23:11 +02:00
|
|
|
}
|
2011-12-23 13:54:26 +01:00
|
|
|
| TK_INSERT TK_INTO table TK_LP collist TK_RP TK_VALUES TK_LP constlist TK_RP TK_TEMPORARY
|
2005-05-23 18:23:11 +02:00
|
|
|
{
|
|
|
|
SQL_input *sql = (SQL_input*) info;
|
2006-10-31 06:34:07 +01:00
|
|
|
MSIVIEW *insert = NULL;
|
2004-03-20 20:18:46 +01:00
|
|
|
|
2006-10-31 06:34:07 +01:00
|
|
|
INSERT_CreateView( sql->db, &insert, $3, $5, $9, TRUE );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !insert )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, insert );
|
2005-05-23 18:23:11 +02:00
|
|
|
}
|
2004-03-16 20:18:22 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
onecreate:
|
|
|
|
TK_CREATE TK_TABLE table TK_LP table_def TK_RP
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2006-10-31 06:34:07 +01:00
|
|
|
MSIVIEW *create = NULL;
|
2009-02-26 04:45:22 +01:00
|
|
|
UINT r;
|
2004-03-16 20:18:22 +01:00
|
|
|
|
|
|
|
if( !$5 )
|
|
|
|
YYABORT;
|
2009-02-26 04:45:22 +01:00
|
|
|
r = CREATE_CreateView( sql->db, &create, $3, $5, FALSE );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !create )
|
2009-02-26 04:45:22 +01:00
|
|
|
{
|
|
|
|
sql->r = r;
|
2005-05-23 18:23:11 +02:00
|
|
|
YYABORT;
|
2009-02-26 04:45:22 +01:00
|
|
|
}
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, create );
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
| TK_CREATE TK_TABLE table TK_LP table_def TK_RP TK_HOLD
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2006-10-31 06:34:07 +01:00
|
|
|
MSIVIEW *create = NULL;
|
2004-03-16 20:18:22 +01:00
|
|
|
|
|
|
|
if( !$5 )
|
|
|
|
YYABORT;
|
|
|
|
CREATE_CreateView( sql->db, &create, $3, $5, TRUE );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !create )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, create );
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-07-04 02:30:02 +02:00
|
|
|
oneupdate:
|
|
|
|
TK_UPDATE table TK_SET update_assign_list TK_WHERE expr
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2006-10-26 10:40:47 +02:00
|
|
|
MSIVIEW *update = NULL;
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2005-05-29 22:17:16 +02:00
|
|
|
UPDATE_CreateView( sql->db, &update, $2, $4, $6 );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !update )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, update );
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
2006-10-26 10:40:47 +02:00
|
|
|
| TK_UPDATE table TK_SET update_assign_list
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
MSIVIEW *update = NULL;
|
|
|
|
|
|
|
|
UPDATE_CreateView( sql->db, &update, $2, $4, NULL );
|
|
|
|
if( !update )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, update );
|
2006-10-26 10:40:47 +02:00
|
|
|
}
|
2004-07-04 02:30:02 +02:00
|
|
|
;
|
|
|
|
|
2005-02-14 12:07:13 +01:00
|
|
|
onedelete:
|
|
|
|
TK_DELETE from
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2006-10-31 06:34:07 +01:00
|
|
|
MSIVIEW *delete = NULL;
|
2005-02-14 12:07:13 +01:00
|
|
|
|
|
|
|
DELETE_CreateView( sql->db, &delete, $2 );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !delete )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, delete );
|
2005-02-14 12:07:13 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2006-08-18 07:09:03 +02:00
|
|
|
onealter:
|
|
|
|
TK_ALTER TK_TABLE table alterop
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
MSIVIEW *alter = NULL;
|
|
|
|
|
2007-07-20 23:01:13 +02:00
|
|
|
ALTER_CreateView( sql->db, &alter, $3, NULL, $4 );
|
2006-08-18 07:09:03 +02:00
|
|
|
if( !alter )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, alter );
|
2007-07-20 23:01:13 +02:00
|
|
|
}
|
|
|
|
| TK_ALTER TK_TABLE table TK_ADD column_and_type
|
|
|
|
{
|
|
|
|
SQL_input *sql = (SQL_input *)info;
|
|
|
|
MSIVIEW *alter = NULL;
|
|
|
|
|
|
|
|
ALTER_CreateView( sql->db, &alter, $3, $5, 0 );
|
|
|
|
if (!alter)
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, alter );
|
2006-08-18 07:09:03 +02:00
|
|
|
}
|
2007-07-21 03:41:16 +02:00
|
|
|
| TK_ALTER TK_TABLE table TK_ADD column_and_type TK_HOLD
|
|
|
|
{
|
|
|
|
SQL_input *sql = (SQL_input *)info;
|
|
|
|
MSIVIEW *alter = NULL;
|
|
|
|
|
|
|
|
ALTER_CreateView( sql->db, &alter, $3, $5, 1 );
|
|
|
|
if (!alter)
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, alter );
|
2007-07-21 03:41:16 +02:00
|
|
|
}
|
2006-08-18 07:09:03 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
alterop:
|
|
|
|
TK_HOLD
|
|
|
|
{
|
|
|
|
$$ = 1;
|
|
|
|
}
|
|
|
|
| TK_FREE
|
|
|
|
{
|
|
|
|
$$ = -1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2008-10-02 22:56:54 +02:00
|
|
|
onedrop:
|
|
|
|
TK_DROP TK_TABLE table
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2009-12-16 03:18:31 +01:00
|
|
|
MSIVIEW* drop = NULL;
|
2008-10-02 22:56:54 +02:00
|
|
|
UINT r;
|
|
|
|
|
2009-12-16 03:18:31 +01:00
|
|
|
r = DROP_CreateView( sql->db, &drop, $3 );
|
2008-10-02 22:56:54 +02:00
|
|
|
if( r != ERROR_SUCCESS || !$$ )
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, drop );
|
2008-10-02 22:56:54 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-03-16 20:18:22 +01:00
|
|
|
table_def:
|
2011-12-23 13:54:26 +01:00
|
|
|
column_def TK_PRIMARY TK_KEY collist
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2009-03-02 06:41:30 +01:00
|
|
|
if( SQL_MarkPrimaryKeys( &$1, $4 ) )
|
2004-03-16 20:18:22 +01:00
|
|
|
$$ = $1;
|
|
|
|
else
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column_def:
|
2005-05-29 22:17:16 +02:00
|
|
|
column_def TK_COMMA column_and_type
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
column_info *ci;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
for( ci = $1; ci->next; ci = ci->next )
|
|
|
|
;
|
|
|
|
|
2005-05-29 22:17:16 +02:00
|
|
|
ci->next = $3;
|
2004-03-19 02:16:36 +01:00
|
|
|
$$ = $1;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
2005-05-29 22:17:16 +02:00
|
|
|
| column_and_type
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column_and_type:
|
|
|
|
column column_type
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2007-07-21 03:41:16 +02:00
|
|
|
$$->type = ($2 | MSITYPE_VALID);
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column_type:
|
2004-03-19 02:16:36 +01:00
|
|
|
data_type_l
|
|
|
|
{
|
2005-09-28 13:59:40 +02:00
|
|
|
$$ = $1;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
|
|
|
| data_type_l TK_LOCALIZABLE
|
|
|
|
{
|
2005-09-28 13:59:40 +02:00
|
|
|
$$ = $1 | MSITYPE_LOCALIZABLE;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
2006-09-08 11:25:40 +02:00
|
|
|
| data_type_l TK_TEMPORARY
|
|
|
|
{
|
2007-04-23 09:26:44 +02:00
|
|
|
$$ = $1 | MSITYPE_TEMPORARY;
|
2006-09-08 11:25:40 +02:00
|
|
|
}
|
2004-03-19 02:16:36 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
data_type_l:
|
2004-03-16 20:18:22 +01:00
|
|
|
data_type
|
|
|
|
{
|
|
|
|
$$ |= MSITYPE_NULLABLE;
|
|
|
|
}
|
|
|
|
| data_type TK_NOT TK_NULL
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
data_type:
|
|
|
|
TK_CHAR
|
|
|
|
{
|
2016-02-15 10:16:12 +01:00
|
|
|
$$ = MSITYPE_STRING | 0x400;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
| TK_CHAR TK_LP data_count TK_RP
|
|
|
|
{
|
2004-07-04 02:27:48 +02:00
|
|
|
$$ = MSITYPE_STRING | 0x400 | $3;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
| TK_LONGCHAR
|
|
|
|
{
|
2009-04-25 21:38:06 +02:00
|
|
|
$$ = MSITYPE_STRING | 0x400;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
| TK_SHORT
|
|
|
|
{
|
2009-04-25 21:36:27 +02:00
|
|
|
$$ = 2 | 0x400;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
| TK_INT
|
|
|
|
{
|
2009-04-25 21:35:10 +02:00
|
|
|
$$ = 2 | 0x400;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
| TK_LONG
|
|
|
|
{
|
|
|
|
$$ = 4;
|
|
|
|
}
|
|
|
|
| TK_OBJECT
|
|
|
|
{
|
2005-09-28 13:59:40 +02:00
|
|
|
$$ = MSITYPE_STRING | MSITYPE_VALID;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
data_count:
|
2005-05-31 11:30:01 +02:00
|
|
|
number
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2005-05-31 11:30:01 +02:00
|
|
|
if( ( $1 > 255 ) || ( $1 < 0 ) )
|
2004-03-16 20:18:22 +01:00
|
|
|
YYABORT;
|
2005-05-31 11:30:01 +02:00
|
|
|
$$ = $1;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
oneselect:
|
2005-05-23 13:49:49 +02:00
|
|
|
TK_SELECT selectfrom
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| TK_SELECT TK_DISTINCT selectfrom
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2009-12-16 03:18:31 +01:00
|
|
|
MSIVIEW* distinct = NULL;
|
2005-09-26 12:55:18 +02:00
|
|
|
UINT r;
|
2005-05-23 13:49:49 +02:00
|
|
|
|
2009-12-16 03:18:31 +01:00
|
|
|
r = DISTINCT_CreateView( sql->db, &distinct, $3 );
|
2005-09-26 12:55:18 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2003-08-13 03:27:48 +02:00
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, distinct );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2005-05-23 13:49:49 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
selectfrom:
|
2006-10-31 08:16:51 +01:00
|
|
|
selcollist from
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2009-12-16 03:18:31 +01:00
|
|
|
MSIVIEW* select = NULL;
|
2005-09-26 12:55:18 +02:00
|
|
|
UINT r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-05-23 13:49:49 +02:00
|
|
|
if( $1 )
|
2005-09-26 12:55:18 +02:00
|
|
|
{
|
2009-12-16 03:18:31 +01:00
|
|
|
r = SELECT_CreateView( sql->db, &select, $2, $1 );
|
2005-09-26 12:55:18 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, select );
|
2005-09-26 12:55:18 +02:00
|
|
|
}
|
2005-05-23 13:49:49 +02:00
|
|
|
else
|
|
|
|
$$ = $2;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
selcollist:
|
2011-12-23 13:54:26 +01:00
|
|
|
selcolumn
|
|
|
|
| selcolumn TK_COMMA selcollist
|
|
|
|
{
|
|
|
|
$1->next = $3;
|
|
|
|
}
|
|
|
|
| TK_STAR
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
collist:
|
2006-10-31 06:34:07 +01:00
|
|
|
column
|
2011-12-23 13:54:26 +01:00
|
|
|
| column TK_COMMA collist
|
2006-10-31 06:34:07 +01:00
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
$1->next = $3;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| TK_STAR
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
from:
|
2011-10-20 14:22:25 +02:00
|
|
|
TK_FROM table
|
2006-10-31 06:34:07 +01:00
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2011-10-20 14:22:25 +02:00
|
|
|
MSIVIEW* table = NULL;
|
2004-07-19 21:35:05 +02:00
|
|
|
UINT r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-10-20 14:22:25 +02:00
|
|
|
r = TABLE_CreateView( sql->db, $2, &table );
|
|
|
|
if( r != ERROR_SUCCESS || !$$ )
|
2004-07-19 21:35:05 +02:00
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
2011-10-20 14:22:25 +02:00
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, table );
|
|
|
|
}
|
2011-12-23 13:54:26 +01:00
|
|
|
| unorderdfrom TK_ORDER TK_BY collist
|
2011-10-20 14:22:25 +02:00
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
if( $4 )
|
|
|
|
{
|
|
|
|
r = $1->ops->sort( $1, $4 );
|
|
|
|
if ( r != ERROR_SUCCESS)
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
$$ = $1;
|
2011-10-20 14:22:20 +02:00
|
|
|
}
|
2011-10-20 14:22:25 +02:00
|
|
|
| unorderdfrom
|
|
|
|
;
|
|
|
|
|
|
|
|
unorderdfrom:
|
|
|
|
TK_FROM tablelist
|
2011-10-20 14:22:20 +02:00
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
MSIVIEW* where = NULL;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
r = WHERE_CreateView( sql->db, &where, $2, NULL );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
YYABORT;
|
|
|
|
|
2009-12-16 03:18:31 +01:00
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, where );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2011-10-20 14:22:25 +02:00
|
|
|
| TK_FROM tablelist TK_WHERE expr
|
2005-05-24 11:49:01 +02:00
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2011-10-20 14:22:25 +02:00
|
|
|
MSIVIEW* where = NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT r;
|
|
|
|
|
2011-10-20 14:22:25 +02:00
|
|
|
r = WHERE_CreateView( sql->db, &where, $2, $4 );
|
|
|
|
if( r != ERROR_SUCCESS )
|
2003-08-13 03:27:48 +02:00
|
|
|
YYABORT;
|
2009-12-16 03:18:31 +01:00
|
|
|
|
2011-10-20 14:22:25 +02:00
|
|
|
PARSER_BUBBLE_UP_VIEW( sql, $$, where );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
tablelist:
|
|
|
|
table
|
|
|
|
{
|
2009-05-28 15:03:49 +02:00
|
|
|
$$ = $1;
|
2007-08-01 23:25:45 +02:00
|
|
|
}
|
2011-12-23 13:54:26 +01:00
|
|
|
| table TK_COMMA tablelist
|
2007-08-01 23:25:45 +02:00
|
|
|
{
|
2009-05-28 15:03:49 +02:00
|
|
|
$$ = parser_add_table( info, $3, $1 );
|
2007-08-01 23:25:45 +02:00
|
|
|
if (!$$)
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
expr:
|
|
|
|
TK_LP expr TK_RP
|
|
|
|
{
|
|
|
|
$$ = $2;
|
2005-05-23 14:08:17 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| expr TK_AND expr
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_AND, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| expr TK_OR expr
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_OR, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_EQ val
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_EQ, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_GT val
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_GT, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_LT val
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_LT, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_LE val
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_LE, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_GE val
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_GE, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_NE val
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_complex( info, $1, OP_NE, $3 );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_IS TK_NULL
|
|
|
|
{
|
2006-11-07 07:07:16 +01:00
|
|
|
$$ = EXPR_unary( info, $1, OP_ISNULL );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| column_val TK_IS TK_NOT TK_NULL
|
|
|
|
{
|
2006-11-07 07:07:16 +01:00
|
|
|
$$ = EXPR_unary( info, $1, OP_NOTNULL );
|
2005-05-23 11:53:43 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
val:
|
|
|
|
column_val
|
2004-03-20 20:18:46 +01:00
|
|
|
| const_val
|
2004-06-30 20:18:27 +02:00
|
|
|
;
|
2004-03-20 20:18:46 +01:00
|
|
|
|
|
|
|
constlist:
|
|
|
|
const_val
|
|
|
|
{
|
2005-05-30 13:32:18 +02:00
|
|
|
$$ = parser_alloc_column( info, NULL, NULL );
|
|
|
|
if( !$$ )
|
2005-05-23 14:08:17 +02:00
|
|
|
YYABORT;
|
2005-05-30 13:32:18 +02:00
|
|
|
$$->val = $1;
|
2004-03-20 20:18:46 +01:00
|
|
|
}
|
2005-01-20 21:39:15 +01:00
|
|
|
| const_val TK_COMMA constlist
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-30 13:32:18 +02:00
|
|
|
$$ = parser_alloc_column( info, NULL, NULL );
|
|
|
|
if( !$$ )
|
2005-05-23 14:08:17 +02:00
|
|
|
YYABORT;
|
2005-05-30 13:32:18 +02:00
|
|
|
$$->val = $1;
|
|
|
|
$$->next = $3;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2004-07-04 02:30:02 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
update_assign_list:
|
|
|
|
column_assignment
|
|
|
|
| column_assignment TK_COMMA update_assign_list
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2005-05-29 22:17:16 +02:00
|
|
|
$$->next = $3;
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column_assignment:
|
|
|
|
column TK_EQ const_val
|
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
$$ = $1;
|
|
|
|
$$->val = $3;
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
|
|
|
;
|
2004-03-20 20:18:46 +01:00
|
|
|
|
|
|
|
const_val:
|
2005-05-31 11:30:01 +02:00
|
|
|
number
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-31 11:30:01 +02:00
|
|
|
$$ = EXPR_ival( info, $1 );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2004-12-16 15:33:56 +01:00
|
|
|
}
|
2006-02-07 16:24:51 +01:00
|
|
|
| TK_MINUS number %prec TK_NEGATION
|
2004-12-16 15:33:56 +01:00
|
|
|
{
|
2005-05-31 11:30:01 +02:00
|
|
|
$$ = EXPR_ival( info, -$2 );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| TK_STRING
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_sval( info, &$1 );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2004-06-30 20:24:33 +02:00
|
|
|
| TK_WILDCARD
|
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_wildcard( info );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2004-06-30 20:24:33 +02:00
|
|
|
}
|
2018-04-18 17:59:25 +02:00
|
|
|
| TK_NULL
|
|
|
|
{
|
|
|
|
$$ = EXPR_sval( info, NULL );
|
|
|
|
if ( !$$ )
|
|
|
|
YYABORT;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
column_val:
|
2006-10-31 06:34:07 +01:00
|
|
|
column
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
$$ = EXPR_column( info, $1 );
|
2005-05-23 18:23:11 +02:00
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column:
|
2005-05-19 13:15:37 +02:00
|
|
|
table TK_DOT id
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
$$ = parser_alloc_column( info, $1, $3 );
|
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2005-05-19 13:15:37 +02:00
|
|
|
| id
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
$$ = parser_alloc_column( info, NULL, $1 );
|
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2011-12-23 13:54:26 +01:00
|
|
|
selcolumn:
|
|
|
|
table TK_DOT id
|
|
|
|
{
|
|
|
|
$$ = parser_alloc_column( info, $1, $3 );
|
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
| id
|
|
|
|
{
|
|
|
|
$$ = parser_alloc_column( info, NULL, $1 );
|
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
| string
|
|
|
|
{
|
|
|
|
$$ = parser_alloc_column( info, NULL, $1 );
|
|
|
|
if( !$$ )
|
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
table:
|
2005-05-19 13:15:37 +02:00
|
|
|
id
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2005-05-19 13:15:37 +02:00
|
|
|
id:
|
2003-08-13 03:27:48 +02:00
|
|
|
TK_ID
|
|
|
|
{
|
2009-02-26 04:43:54 +01:00
|
|
|
if ( SQL_getstring( info, &$1, &$$ ) != ERROR_SUCCESS || !$$ )
|
2005-05-23 14:08:17 +02:00
|
|
|
YYABORT;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2011-12-23 13:54:26 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
string:
|
|
|
|
TK_STRING
|
|
|
|
{
|
|
|
|
if ( SQL_getstring( info, &$1, &$$ ) != ERROR_SUCCESS || !$$ )
|
|
|
|
YYABORT;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
;
|
|
|
|
|
2005-05-31 11:30:01 +02:00
|
|
|
number:
|
|
|
|
TK_INTEGER
|
|
|
|
{
|
|
|
|
$$ = SQL_getint( info );
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
%%
|
|
|
|
|
2009-05-28 15:03:49 +02:00
|
|
|
static LPWSTR parser_add_table( void *info, LPCWSTR list, LPCWSTR table )
|
2007-08-01 23:25:45 +02:00
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
DWORD len = lstrlenW( list ) + lstrlenW( table ) + 2;
|
2009-05-28 15:03:49 +02:00
|
|
|
LPWSTR ret;
|
2007-08-01 23:25:45 +02:00
|
|
|
|
2009-05-28 15:03:49 +02:00
|
|
|
ret = parser_alloc( info, len * sizeof(WCHAR) );
|
|
|
|
if( ret )
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW( ret, list );
|
2020-10-29 11:47:14 +01:00
|
|
|
lstrcatW( ret, L" " );
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcatW( ret, table );
|
2009-05-28 15:03:49 +02:00
|
|
|
}
|
|
|
|
return ret;
|
2007-08-01 23:25:45 +02:00
|
|
|
}
|
|
|
|
|
2005-05-23 14:08:17 +02:00
|
|
|
static void *parser_alloc( void *info, unsigned int sz )
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
struct list *mem;
|
|
|
|
|
2005-09-20 13:57:19 +02:00
|
|
|
mem = msi_alloc( sizeof (struct list) + sz );
|
2005-05-23 14:08:17 +02:00
|
|
|
list_add_tail( sql->mem, mem );
|
|
|
|
return &mem[1];
|
|
|
|
}
|
|
|
|
|
2005-05-29 22:17:16 +02:00
|
|
|
static column_info *parser_alloc_column( void *info, LPCWSTR table, LPCWSTR column )
|
|
|
|
{
|
|
|
|
column_info *col;
|
|
|
|
|
|
|
|
col = parser_alloc( info, sizeof (*col) );
|
|
|
|
if( col )
|
|
|
|
{
|
|
|
|
col->table = table;
|
|
|
|
col->column = column;
|
|
|
|
col->val = NULL;
|
|
|
|
col->type = 0;
|
|
|
|
col->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
2006-09-11 21:53:04 +02:00
|
|
|
static int sql_lex( void *SQL_lval, SQL_input *sql )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2012-01-03 13:53:14 +01:00
|
|
|
int token, skip;
|
2004-06-26 02:11:08 +02:00
|
|
|
struct sql_str * str = SQL_lval;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sql->n += sql->len;
|
|
|
|
if( ! sql->command[sql->n] )
|
|
|
|
return 0; /* end of input */
|
|
|
|
|
2005-09-26 12:55:18 +02:00
|
|
|
/* TRACE("string : %s\n", debugstr_w(&sql->command[sql->n])); */
|
2012-01-03 13:53:14 +01:00
|
|
|
sql->len = sqliteGetToken( &sql->command[sql->n], &token, &skip );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( sql->len==0 )
|
|
|
|
break;
|
2004-06-26 02:11:08 +02:00
|
|
|
str->data = &sql->command[sql->n];
|
|
|
|
str->len = sql->len;
|
2012-01-03 13:53:14 +01:00
|
|
|
sql->n += skip;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
while( token == TK_SPACE );
|
|
|
|
|
2005-09-26 12:55:18 +02:00
|
|
|
/* TRACE("token : %d (%s)\n", token, debugstr_wn(&sql->command[sql->n], sql->len)); */
|
2006-10-31 06:34:07 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2009-02-26 04:43:54 +01:00
|
|
|
UINT SQL_getstring( void *info, const struct sql_str *strdata, LPWSTR *str )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
LPCWSTR p = strdata->data;
|
|
|
|
UINT len = strdata->len;
|
2009-02-26 04:43:54 +01:00
|
|
|
|
|
|
|
/* match quotes */
|
|
|
|
if( ( (p[0]=='`') && (p[len-1]!='`') ) ||
|
|
|
|
( (p[0]=='\'') && (p[len-1]!='\'') ) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2013-11-20 23:39:28 +01:00
|
|
|
/* if there are quotes, remove them */
|
2006-10-31 06:34:07 +01:00
|
|
|
if( ( (p[0]=='`') && (p[len-1]=='`') ) ||
|
2004-06-28 22:34:35 +02:00
|
|
|
( (p[0]=='\'') && (p[len-1]=='\'') ) )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
p++;
|
|
|
|
len -= 2;
|
|
|
|
}
|
2009-02-26 04:43:54 +01:00
|
|
|
*str = parser_alloc( info, (len + 1)*sizeof(WCHAR) );
|
|
|
|
if( !*str )
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
memcpy( *str, p, len*sizeof(WCHAR) );
|
|
|
|
(*str)[len]=0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-02-26 04:43:54 +01:00
|
|
|
return ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2005-05-23 14:08:17 +02:00
|
|
|
INT SQL_getint( void *info )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2003-08-13 03:27:48 +02:00
|
|
|
LPCWSTR p = &sql->command[sql->n];
|
2005-05-31 11:30:01 +02:00
|
|
|
INT i, r = 0;
|
|
|
|
|
|
|
|
for( i=0; i<sql->len; i++ )
|
|
|
|
{
|
|
|
|
if( '0' > p[i] || '9' < p[i] )
|
|
|
|
{
|
|
|
|
ERR("should only be numbers here!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
r = (p[i]-'0') + r*10;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-05-31 11:30:01 +02:00
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 12:00:04 +02:00
|
|
|
static int sql_error( SQL_input *info, const char *str )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-23 14:08:17 +02:00
|
|
|
static struct expr * EXPR_wildcard( void *info )
|
2004-06-30 20:18:27 +02:00
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
struct expr *e = parser_alloc( info, sizeof *e );
|
2004-06-30 20:18:27 +02:00
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_WILDCARD;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2005-05-23 14:08:17 +02:00
|
|
|
static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct expr *r )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
struct expr *e = parser_alloc( info, sizeof *e );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_COMPLEX;
|
|
|
|
e->u.expr.left = l;
|
|
|
|
e->u.expr.op = op;
|
|
|
|
e->u.expr.right = r;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2006-11-07 07:07:16 +01:00
|
|
|
static struct expr * EXPR_unary( void *info, struct expr *l, UINT op )
|
|
|
|
{
|
|
|
|
struct expr *e = parser_alloc( info, sizeof *e );
|
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_UNARY;
|
|
|
|
e->u.expr.left = l;
|
|
|
|
e->u.expr.op = op;
|
|
|
|
e->u.expr.right = NULL;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2007-06-12 22:51:36 +02:00
|
|
|
static struct expr * EXPR_column( void *info, const column_info *column )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
struct expr *e = parser_alloc( info, sizeof *e );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_COLUMN;
|
2011-08-26 04:53:34 +02:00
|
|
|
e->u.column.unparsed.column = column->column;
|
|
|
|
e->u.column.unparsed.table = column->table;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:30:01 +02:00
|
|
|
static struct expr * EXPR_ival( void *info, int val )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
struct expr *e = parser_alloc( info, sizeof *e );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_IVAL;
|
2005-05-31 11:30:01 +02:00
|
|
|
e->u.ival = val;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2007-06-12 22:51:36 +02:00
|
|
|
static struct expr * EXPR_sval( void *info, const struct sql_str *str )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-23 14:08:17 +02:00
|
|
|
struct expr *e = parser_alloc( info, sizeof *e );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_SVAL;
|
2018-04-18 17:59:25 +02:00
|
|
|
if( !str) e->u.sval = NULL;
|
|
|
|
else if( SQL_getstring( info, str, (LPWSTR *)&e->u.sval ) != ERROR_SUCCESS )
|
2009-04-20 16:09:12 +02:00
|
|
|
return NULL; /* e will be freed by query destructor */
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2009-03-02 06:41:30 +01:00
|
|
|
static void swap_columns( column_info **cols, column_info *A, int idx )
|
|
|
|
{
|
|
|
|
column_info *preA = NULL, *preB = NULL, *B, *ptr;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
B = NULL;
|
|
|
|
ptr = *cols;
|
|
|
|
while( ptr )
|
|
|
|
{
|
|
|
|
if( i++ == idx )
|
|
|
|
B = ptr;
|
|
|
|
else if( !B )
|
|
|
|
preB = ptr;
|
|
|
|
|
|
|
|
if( ptr->next == A )
|
|
|
|
preA = ptr;
|
|
|
|
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( preB ) preB->next = A;
|
|
|
|
if( preA ) preA->next = B;
|
|
|
|
ptr = A->next;
|
|
|
|
A->next = B->next;
|
|
|
|
B->next = ptr;
|
|
|
|
if( idx == 0 )
|
|
|
|
*cols = A;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SQL_MarkPrimaryKeys( column_info **cols,
|
2005-05-29 22:17:16 +02:00
|
|
|
column_info *keys )
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
column_info *k;
|
2004-03-16 20:18:22 +01:00
|
|
|
BOOL found = TRUE;
|
2009-03-02 06:41:30 +01:00
|
|
|
int count;
|
2004-03-16 20:18:22 +01:00
|
|
|
|
2009-03-02 06:41:30 +01:00
|
|
|
for( k = keys, count = 0; k && found; k = k->next, count++ )
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2005-05-29 22:17:16 +02:00
|
|
|
column_info *c;
|
2009-03-02 06:41:30 +01:00
|
|
|
int idx;
|
2004-03-16 20:18:22 +01:00
|
|
|
|
|
|
|
found = FALSE;
|
2009-03-02 06:41:30 +01:00
|
|
|
for( c = *cols, idx = 0; c && !found; c = c->next, idx++ )
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
if( wcscmp( k->column, c->column ) )
|
2009-03-02 06:41:30 +01:00
|
|
|
continue;
|
|
|
|
c->type |= MSITYPE_KEY;
|
|
|
|
found = TRUE;
|
|
|
|
if (idx != count)
|
|
|
|
swap_columns( cols, c, count );
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2005-05-23 14:08:17 +02:00
|
|
|
UINT MSI_ParseSQL( MSIDATABASE *db, LPCWSTR command, MSIVIEW **phview,
|
|
|
|
struct list *mem )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input sql;
|
2003-08-13 03:27:48 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
*phview = NULL;
|
|
|
|
|
|
|
|
sql.db = db;
|
|
|
|
sql.command = command;
|
|
|
|
sql.n = 0;
|
|
|
|
sql.len = 0;
|
2009-02-26 04:45:22 +01:00
|
|
|
sql.r = ERROR_BAD_QUERY_SYNTAX;
|
2003-08-13 03:27:48 +02:00
|
|
|
sql.view = phview;
|
2005-05-23 14:08:17 +02:00
|
|
|
sql.mem = mem;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2006-09-11 21:53:04 +02:00
|
|
|
r = sql_parse(&sql);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("Parse returned %d\n", r);
|
|
|
|
if( r )
|
|
|
|
{
|
2009-03-02 11:33:48 +01:00
|
|
|
if (*sql.view)
|
|
|
|
{
|
|
|
|
(*sql.view)->ops->delete(*sql.view);
|
|
|
|
*sql.view = NULL;
|
|
|
|
}
|
2009-02-26 04:45:22 +01:00
|
|
|
return sql.r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|