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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
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"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
#define YYLEX_PARAM info
|
|
|
|
#define YYPARSE_PARAM info
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
extern int SQL_error(const char *str);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
typedef struct tag_SQL_input
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIDATABASE *db;
|
|
|
|
LPCWSTR command;
|
|
|
|
DWORD n, len;
|
|
|
|
MSIVIEW **view; /* view structure for the resulting query */
|
2004-03-16 04:23:43 +01:00
|
|
|
} SQL_input;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
static LPWSTR SQL_getstring( struct sql_str *str );
|
2004-03-16 04:23:43 +01:00
|
|
|
static INT SQL_getint( SQL_input *sql );
|
|
|
|
static int SQL_lex( void *SQL_lval, SQL_input *info);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
static MSIVIEW *do_one_select( MSIDATABASE *db, MSIVIEW *in,
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *columns );
|
2003-08-13 03:27:48 +02:00
|
|
|
static MSIVIEW *do_order_by( MSIDATABASE *db, MSIVIEW *in,
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *columns );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-03-16 20:18:22 +01:00
|
|
|
static BOOL SQL_MarkPrimaryKeys( create_col_info *cols,
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *keys);
|
2004-03-16 20:18:22 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
static struct expr * EXPR_complex( struct expr *l, UINT op, struct expr *r );
|
2004-06-26 02:11:08 +02:00
|
|
|
static struct expr * EXPR_column( LPWSTR );
|
|
|
|
static struct expr * EXPR_ival( struct sql_str *);
|
|
|
|
static struct expr * EXPR_sval( struct sql_str *);
|
2004-06-30 20:18:27 +02:00
|
|
|
static struct expr * EXPR_wildcard();
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%pure-parser
|
|
|
|
|
|
|
|
%union
|
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
struct sql_str str;
|
2003-08-13 03:27:48 +02:00
|
|
|
LPWSTR string;
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *column_list;
|
|
|
|
value_list *val_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;
|
|
|
|
create_col_info *column_info;
|
2004-07-04 02:30:02 +02:00
|
|
|
column_assignment update_col_info;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
%token TK_ABORT TK_AFTER TK_AGG_FUNCTION TK_ALL TK_AND TK_AS TK_ASC
|
|
|
|
%token TK_BEFORE TK_BEGIN TK_BETWEEN TK_BITAND TK_BITNOT TK_BITOR TK_BY
|
2004-03-16 20:18:22 +01:00
|
|
|
%token TK_CASCADE TK_CASE TK_CHAR TK_CHECK TK_CLUSTER TK_COLLATE TK_COLUMN
|
|
|
|
%token TK_COMMA TK_COMMENT TK_COMMIT TK_CONCAT TK_CONFLICT
|
2003-08-13 03:27:48 +02:00
|
|
|
%token TK_CONSTRAINT TK_COPY TK_CREATE
|
|
|
|
%token TK_DEFAULT TK_DEFERRABLE TK_DEFERRED TK_DELETE TK_DELIMITERS TK_DESC
|
|
|
|
%token TK_DISTINCT TK_DOT TK_DROP TK_EACH
|
|
|
|
%token TK_ELSE TK_END TK_END_OF_FILE TK_EQ TK_EXCEPT TK_EXPLAIN
|
|
|
|
%token TK_FAIL TK_FLOAT TK_FOR TK_FOREIGN TK_FROM TK_FUNCTION
|
|
|
|
%token TK_GE TK_GLOB TK_GROUP TK_GT
|
2004-03-16 20:18:22 +01:00
|
|
|
%token TK_HAVING TK_HOLD
|
2003-08-13 03:27:48 +02:00
|
|
|
%token TK_IGNORE TK_ILLEGAL TK_IMMEDIATE TK_IN TK_INDEX TK_INITIALLY
|
2004-06-26 02:11:08 +02:00
|
|
|
%token <str> TK_ID
|
|
|
|
%token TK_INSERT TK_INSTEAD TK_INT
|
|
|
|
%token <str> TK_INTEGER
|
|
|
|
%token TK_INTERSECT TK_INTO TK_IS
|
2004-03-19 02:16:36 +01:00
|
|
|
%token TK_ISNULL
|
2003-08-13 03:27:48 +02:00
|
|
|
%token TK_JOIN TK_JOIN_KW
|
|
|
|
%token TK_KEY
|
2004-03-16 20:18:22 +01:00
|
|
|
%token TK_LE TK_LIKE TK_LIMIT TK_LONG TK_LONGCHAR TK_LP TK_LSHIFT TK_LT
|
2004-03-19 02:16:36 +01:00
|
|
|
%token TK_LOCALIZABLE
|
2003-08-13 03:27:48 +02:00
|
|
|
%token TK_MATCH TK_MINUS
|
|
|
|
%token TK_NE TK_NOT TK_NOTNULL TK_NULL
|
2004-03-16 20:18:22 +01:00
|
|
|
%token TK_OBJECT TK_OF TK_OFFSET TK_ON TK_OR TK_ORACLE_OUTER_JOIN TK_ORDER
|
2003-08-13 03:27:48 +02:00
|
|
|
%token TK_PLUS TK_PRAGMA TK_PRIMARY
|
|
|
|
%token TK_RAISE TK_REFERENCES TK_REM TK_REPLACE TK_RESTRICT TK_ROLLBACK
|
|
|
|
%token TK_ROW TK_RP TK_RSHIFT
|
2004-03-16 20:18:22 +01:00
|
|
|
%token TK_SELECT TK_SEMI TK_SET TK_SHORT TK_SLASH TK_SPACE TK_STAR TK_STATEMENT
|
2004-06-26 02:11:08 +02:00
|
|
|
%token <str> TK_STRING
|
2003-08-13 03:27:48 +02:00
|
|
|
%token TK_TABLE TK_TEMP TK_THEN TK_TRANSACTION TK_TRIGGER
|
|
|
|
%token TK_UMINUS TK_UNCLOSED_STRING TK_UNION TK_UNIQUE
|
|
|
|
%token TK_UPDATE TK_UPLUS TK_USING
|
|
|
|
%token TK_VACUUM TK_VALUES TK_VIEW
|
2004-06-30 20:18:27 +02:00
|
|
|
%token TK_WHEN 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.
|
|
|
|
|
|
|
|
%type <string> column table string_or_id
|
|
|
|
%type <column_list> selcollist
|
2004-07-04 02:30:02 +02:00
|
|
|
%type <query> from unorderedsel oneselect onequery onecreate oneinsert oneupdate
|
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
|
2004-03-16 20:18:22 +01:00
|
|
|
%type <column_info> column_def table_def
|
2004-03-20 20:18:46 +01:00
|
|
|
%type <val_list> constlist
|
2004-07-04 02:30:02 +02:00
|
|
|
%type <update_col_info> column_assignment update_assign_list
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
2004-03-16 20:18:22 +01:00
|
|
|
onequery:
|
|
|
|
oneselect
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
*sql->view = $1;
|
|
|
|
}
|
|
|
|
| onecreate
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
*sql->view = $1;
|
|
|
|
}
|
2004-03-20 20:18:46 +01:00
|
|
|
| oneinsert
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
*sql->view = $1;
|
|
|
|
}
|
2004-07-04 02:30:02 +02:00
|
|
|
| oneupdate
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
*sql->view = $1;
|
|
|
|
}
|
2004-03-20 20:18:46 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
oneinsert:
|
2004-06-30 20:24:33 +02:00
|
|
|
TK_INSERT TK_INTO table TK_LP selcollist TK_RP TK_VALUES TK_LP constlist TK_RP
|
2004-03-20 20:18:46 +01:00
|
|
|
{
|
|
|
|
SQL_input *sql = (SQL_input*) info;
|
|
|
|
MSIVIEW *insert = NULL;
|
|
|
|
|
2004-06-30 20:24:33 +02:00
|
|
|
INSERT_CreateView( sql->db, &insert, $3, $5, $9, FALSE );
|
2004-03-20 20:18:46 +01:00
|
|
|
$$ = insert;
|
|
|
|
}
|
2004-06-30 20:24:33 +02:00
|
|
|
| TK_INSERT TK_INTO table TK_LP selcollist TK_RP TK_VALUES TK_LP constlist TK_RP TK_TEMP
|
2004-03-20 20:18:46 +01:00
|
|
|
{
|
|
|
|
SQL_input *sql = (SQL_input*) info;
|
|
|
|
MSIVIEW *insert = NULL;
|
|
|
|
|
2004-06-30 20:24:33 +02:00
|
|
|
INSERT_CreateView( sql->db, &insert, $3, $5, $9, TRUE );
|
2004-03-20 20:18:46 +01:00
|
|
|
$$ = insert;
|
|
|
|
}
|
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;
|
2004-07-04 02:30:02 +02:00
|
|
|
MSIVIEW *create = NULL;
|
2004-03-16 20:18:22 +01:00
|
|
|
|
|
|
|
if( !$5 )
|
|
|
|
YYABORT;
|
|
|
|
CREATE_CreateView( sql->db, &create, $3, $5, FALSE );
|
|
|
|
$$ = create;
|
|
|
|
}
|
|
|
|
| TK_CREATE TK_TABLE table TK_LP table_def TK_RP TK_HOLD
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2004-07-04 02:30:02 +02:00
|
|
|
MSIVIEW *create = NULL;
|
2004-03-16 20:18:22 +01:00
|
|
|
|
|
|
|
if( !$5 )
|
|
|
|
YYABORT;
|
|
|
|
CREATE_CreateView( sql->db, &create, $3, $5, TRUE );
|
|
|
|
$$ = create;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
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;
|
|
|
|
MSIVIEW *update = NULL;
|
|
|
|
|
|
|
|
UPDATE_CreateView( sql->db, &update, $2, &$4, $6 );
|
|
|
|
$$ = update;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-03-16 20:18:22 +01:00
|
|
|
table_def:
|
|
|
|
column_def TK_PRIMARY TK_KEY selcollist
|
|
|
|
{
|
|
|
|
if( SQL_MarkPrimaryKeys( $1, $4 ) )
|
|
|
|
$$ = $1;
|
|
|
|
else
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column_def:
|
|
|
|
column_def TK_COMMA column column_type
|
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
create_col_info *ci;
|
|
|
|
|
|
|
|
for( ci = $1; ci->next; ci = ci->next )
|
|
|
|
;
|
|
|
|
|
|
|
|
ci->next = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
|
2004-07-04 02:27:48 +02:00
|
|
|
if( !ci->next )
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2004-07-04 02:27:48 +02:00
|
|
|
/* FIXME: free $1 */
|
|
|
|
YYABORT;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
2004-07-04 02:27:48 +02:00
|
|
|
ci->next->colname = $3;
|
|
|
|
ci->next->type = $4;
|
|
|
|
ci->next->next = NULL;
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
$$ = $1;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
| column column_type
|
|
|
|
{
|
|
|
|
$$ = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
|
2004-07-04 02:27:48 +02:00
|
|
|
if( ! $$ )
|
|
|
|
YYABORT;
|
|
|
|
$$->colname = $1;
|
|
|
|
$$->type = $2;
|
|
|
|
$$->next = NULL;
|
2004-03-16 20:18:22 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column_type:
|
2004-03-19 02:16:36 +01:00
|
|
|
data_type_l
|
|
|
|
{
|
2004-07-04 02:27:48 +02:00
|
|
|
$$ = $1 | MSITYPE_VALID;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
|
|
|
| data_type_l TK_LOCALIZABLE
|
|
|
|
{
|
|
|
|
FIXME("LOCALIZABLE ignored\n");
|
2004-07-04 02:27:48 +02:00
|
|
|
$$ = $1 | MSITYPE_VALID;
|
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
|
|
|
|
{
|
|
|
|
$$ = MSITYPE_STRING | 1;
|
|
|
|
}
|
|
|
|
| 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
|
|
|
|
{
|
|
|
|
$$ = 2;
|
|
|
|
}
|
|
|
|
| TK_SHORT
|
|
|
|
{
|
|
|
|
$$ = 2;
|
|
|
|
}
|
|
|
|
| TK_INT
|
|
|
|
{
|
|
|
|
$$ = 2;
|
|
|
|
}
|
|
|
|
| TK_LONG
|
|
|
|
{
|
|
|
|
$$ = 4;
|
|
|
|
}
|
|
|
|
| TK_OBJECT
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
data_count:
|
|
|
|
TK_INTEGER
|
|
|
|
{
|
|
|
|
SQL_input* sql = (SQL_input*) info;
|
|
|
|
int val = SQL_getint(sql);
|
|
|
|
if( ( val > 255 ) || ( val < 0 ) )
|
|
|
|
YYABORT;
|
|
|
|
$$ = val;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
oneselect:
|
|
|
|
unorderedsel TK_ORDER TK_BY selcollist
|
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( !$1 )
|
|
|
|
YYABORT;
|
|
|
|
if( $4 )
|
2004-03-16 20:18:22 +01:00
|
|
|
$$ = do_order_by( sql->db, $1, $4 );
|
2003-08-13 03:27:48 +02:00
|
|
|
else
|
2004-03-16 20:18:22 +01:00
|
|
|
$$ = $1;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| unorderedsel
|
|
|
|
;
|
|
|
|
|
|
|
|
unorderedsel:
|
|
|
|
TK_SELECT selcollist from
|
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !$3 )
|
|
|
|
YYABORT;
|
|
|
|
if( $2 )
|
|
|
|
$$ = do_one_select( sql->db, $3, $2 );
|
|
|
|
else
|
|
|
|
$$ = $3;
|
|
|
|
}
|
|
|
|
| TK_SELECT TK_DISTINCT selcollist from
|
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2003-08-13 03:27:48 +02:00
|
|
|
MSIVIEW *view = $4;
|
|
|
|
|
|
|
|
if( !view )
|
|
|
|
YYABORT;
|
|
|
|
if( $3 )
|
|
|
|
view = do_one_select( sql->db, view, $3 );
|
|
|
|
DISTINCT_CreateView( sql->db, & $$, view );
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
selcollist:
|
|
|
|
column
|
|
|
|
{
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *list;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
list = HeapAlloc( GetProcessHeap(), 0, sizeof *list );
|
|
|
|
if( !list )
|
|
|
|
YYABORT;
|
|
|
|
list->string = $1;
|
|
|
|
list->next = NULL;
|
|
|
|
|
|
|
|
$$ = list;
|
|
|
|
TRACE("Collist %s\n",debugstr_w($$->string));
|
|
|
|
}
|
|
|
|
| column TK_COMMA selcollist
|
|
|
|
{
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *list;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
list = HeapAlloc( GetProcessHeap(), 0, sizeof *list );
|
|
|
|
if( !list )
|
|
|
|
YYABORT;
|
|
|
|
list->string = $1;
|
|
|
|
list->next = $3;
|
|
|
|
|
|
|
|
$$ = list;
|
|
|
|
TRACE("From table: %s\n",debugstr_w($$->string));
|
|
|
|
}
|
|
|
|
| TK_STAR
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
from:
|
|
|
|
TK_FROM table
|
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
$$ = NULL;
|
|
|
|
TRACE("From table: %s\n",debugstr_w($2));
|
|
|
|
TABLE_CreateView( sql->db, $2, & $$ );
|
|
|
|
}
|
|
|
|
| TK_FROM table TK_WHERE expr
|
|
|
|
{
|
2004-03-16 04:23:43 +01:00
|
|
|
SQL_input* sql = (SQL_input*) info;
|
2003-08-13 03:27:48 +02:00
|
|
|
MSIVIEW *view = NULL;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
$$ = NULL;
|
|
|
|
TRACE("From table: %s\n",debugstr_w($2));
|
|
|
|
r = TABLE_CreateView( sql->db, $2, &view );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
YYABORT;
|
2004-07-04 02:27:48 +02:00
|
|
|
r = WHERE_CreateView( sql->db, &view, view, $4 );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
YYABORT;
|
|
|
|
$$ = view;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
expr:
|
|
|
|
TK_LP expr TK_RP
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| column_val TK_EQ column_val
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_EQ, $3 );
|
|
|
|
}
|
|
|
|
| expr TK_AND expr
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_AND, $3 );
|
|
|
|
}
|
|
|
|
| expr TK_OR expr
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_OR, $3 );
|
|
|
|
}
|
|
|
|
| column_val TK_EQ val
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_EQ, $3 );
|
|
|
|
}
|
|
|
|
| column_val TK_GT val
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_GT, $3 );
|
|
|
|
}
|
|
|
|
| column_val TK_LT val
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_LT, $3 );
|
|
|
|
}
|
|
|
|
| column_val TK_LE val
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_LE, $3 );
|
|
|
|
}
|
|
|
|
| column_val TK_GE val
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_GE, $3 );
|
|
|
|
}
|
|
|
|
| column_val TK_NE val
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_NE, $3 );
|
|
|
|
}
|
|
|
|
| column_val TK_IS TK_NULL
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_ISNULL, NULL );
|
|
|
|
}
|
|
|
|
| column_val TK_IS TK_NOT TK_NULL
|
|
|
|
{
|
|
|
|
$$ = EXPR_complex( $1, OP_NOTNULL, NULL );
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
value_list *vals;
|
|
|
|
|
|
|
|
vals = HeapAlloc( GetProcessHeap(), 0, sizeof *vals );
|
|
|
|
if( vals )
|
|
|
|
{
|
|
|
|
vals->val = $1;
|
|
|
|
vals->next = NULL;
|
|
|
|
}
|
|
|
|
$$ = vals;
|
|
|
|
}
|
|
|
|
| constlist TK_COMMA const_val
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-03-20 20:18:46 +01:00
|
|
|
value_list *vals;
|
|
|
|
|
|
|
|
vals = HeapAlloc( GetProcessHeap(), 0, sizeof *vals );
|
|
|
|
if( vals )
|
|
|
|
{
|
|
|
|
vals->val = $3;
|
|
|
|
vals->next = NULL;
|
|
|
|
}
|
|
|
|
$1->next = vals;
|
2003-08-13 03:27:48 +02:00
|
|
|
$$ = $1;
|
|
|
|
}
|
2004-07-04 02:30:02 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
update_assign_list:
|
|
|
|
column_assignment
|
|
|
|
| column_assignment TK_COMMA update_assign_list
|
|
|
|
{
|
|
|
|
$1.col_list->next = $3.col_list;
|
|
|
|
$1.val_list->next = $3.val_list;
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column_assignment:
|
|
|
|
column TK_EQ const_val
|
|
|
|
{
|
|
|
|
$$.col_list = HeapAlloc( GetProcessHeap(), 0, sizeof *$$.col_list );
|
|
|
|
if( !$$.col_list )
|
|
|
|
YYABORT;
|
|
|
|
$$.col_list->string = $1;
|
|
|
|
$$.col_list->next = NULL;
|
|
|
|
$$.val_list = HeapAlloc( GetProcessHeap(), 0, sizeof *$$.val_list );
|
|
|
|
if( !$$.val_list )
|
|
|
|
YYABORT;
|
|
|
|
$$.val_list->val = $3;
|
|
|
|
$$.val_list->next = 0;
|
|
|
|
}
|
|
|
|
;
|
2004-03-20 20:18:46 +01:00
|
|
|
|
|
|
|
const_val:
|
|
|
|
TK_INTEGER
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
$$ = EXPR_ival( &$1 );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| TK_STRING
|
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
$$ = EXPR_sval( &$1 );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2004-06-30 20:24:33 +02:00
|
|
|
| TK_WILDCARD
|
|
|
|
{
|
|
|
|
$$ = EXPR_wildcard();
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
column_val:
|
|
|
|
column
|
|
|
|
{
|
|
|
|
$$ = EXPR_column( $1 );
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
column:
|
|
|
|
table TK_DOT string_or_id
|
|
|
|
{
|
|
|
|
$$ = $3; /* FIXME */
|
|
|
|
}
|
|
|
|
| string_or_id
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
table:
|
|
|
|
string_or_id
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
string_or_id:
|
|
|
|
TK_ID
|
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
$$ = SQL_getstring( &$1 );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
| TK_STRING
|
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
$$ = SQL_getstring( &$1 );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
int SQL_lex( void *SQL_lval, SQL_input *sql)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
int token;
|
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 */
|
|
|
|
|
|
|
|
TRACE("string : %s\n", debugstr_w(&sql->command[sql->n]));
|
|
|
|
sql->len = sqliteGetToken( &sql->command[sql->n], &token );
|
|
|
|
if( sql->len==0 )
|
|
|
|
break;
|
2004-06-26 02:11:08 +02:00
|
|
|
str->data = &sql->command[sql->n];
|
|
|
|
str->len = sql->len;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
while( token == TK_SPACE );
|
|
|
|
|
|
|
|
TRACE("token : %d (%s)\n", token, debugstr_wn(&sql->command[sql->n], sql->len));
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
LPWSTR SQL_getstring( struct sql_str *strdata)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-06-26 02:11:08 +02:00
|
|
|
LPCWSTR p = strdata->data;
|
|
|
|
UINT len = strdata->len;
|
2003-08-13 03:27:48 +02:00
|
|
|
LPWSTR str;
|
|
|
|
|
|
|
|
/* if there's quotes, remove them */
|
2004-06-28 22:34:35 +02:00
|
|
|
if( ( (p[0]=='`') && (p[len-1]=='`') ) ||
|
|
|
|
( (p[0]=='\'') && (p[len-1]=='\'') ) )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
p++;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, (len + 1)*sizeof(WCHAR));
|
|
|
|
if(!str )
|
|
|
|
return str;
|
|
|
|
memcpy(str, p, len*sizeof(WCHAR) );
|
|
|
|
str[len]=0;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
INT SQL_getint( SQL_input *sql )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
LPCWSTR p = &sql->command[sql->n];
|
|
|
|
|
|
|
|
return atoiW( p );
|
|
|
|
}
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
int SQL_error(const char *str)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MSIVIEW *do_one_select( MSIDATABASE *db, MSIVIEW *in,
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *columns )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIVIEW *view = NULL;
|
|
|
|
|
2004-06-30 20:18:27 +02:00
|
|
|
SELECT_CreateView( db, &view, in, columns );
|
|
|
|
delete_string_list( columns );
|
|
|
|
if( !view )
|
2003-08-13 03:27:48 +02:00
|
|
|
ERR("Error creating select query\n");
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MSIVIEW *do_order_by( MSIDATABASE *db, MSIVIEW *in,
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *columns )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIVIEW *view = NULL;
|
|
|
|
|
|
|
|
ORDER_CreateView( db, &view, in );
|
|
|
|
if( view )
|
|
|
|
{
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *x = columns;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-03-20 20:18:46 +01:00
|
|
|
for( x = columns; x ; x = x->next )
|
2003-08-13 03:27:48 +02:00
|
|
|
ORDER_AddColumn( view, x->string );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Error creating select query\n");
|
2004-03-20 20:18:46 +01:00
|
|
|
delete_string_list( columns );
|
2003-08-13 03:27:48 +02:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2004-06-30 20:18:27 +02:00
|
|
|
static struct expr * EXPR_wildcard()
|
|
|
|
{
|
|
|
|
struct expr *e = HeapAlloc( GetProcessHeap(), 0, sizeof *e );
|
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_WILDCARD;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
static struct expr * EXPR_complex( struct expr *l, UINT op, struct expr *r )
|
|
|
|
{
|
|
|
|
struct expr *e = HeapAlloc( GetProcessHeap(), 0, sizeof *e );
|
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_COMPLEX;
|
|
|
|
e->u.expr.left = l;
|
|
|
|
e->u.expr.op = op;
|
|
|
|
e->u.expr.right = r;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
static struct expr * EXPR_column( LPWSTR str )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
struct expr *e = HeapAlloc( GetProcessHeap(), 0, sizeof *e );
|
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_COLUMN;
|
2004-06-26 02:11:08 +02:00
|
|
|
e->u.sval = str;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
static struct expr * EXPR_ival( struct sql_str *str )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
struct expr *e = HeapAlloc( GetProcessHeap(), 0, sizeof *e );
|
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_IVAL;
|
2004-06-26 02:11:08 +02:00
|
|
|
e->u.ival = atoiW( str->data );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
static struct expr * EXPR_sval( struct sql_str *str )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
struct expr *e = HeapAlloc( GetProcessHeap(), 0, sizeof *e );
|
|
|
|
if( e )
|
|
|
|
{
|
|
|
|
e->type = EXPR_SVAL;
|
2004-06-26 02:11:08 +02:00
|
|
|
e->u.sval = SQL_getstring( str );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2004-03-20 20:18:46 +01:00
|
|
|
void delete_expr( struct expr *e )
|
|
|
|
{
|
|
|
|
if( !e )
|
|
|
|
return;
|
|
|
|
if( e->type == EXPR_COMPLEX )
|
|
|
|
{
|
|
|
|
delete_expr( e->u.expr.left );
|
|
|
|
delete_expr( e->u.expr.right );
|
|
|
|
}
|
2004-06-26 02:11:08 +02:00
|
|
|
else if( e->type == EXPR_UTF8 )
|
|
|
|
HeapFree( GetProcessHeap(), 0, e->u.utf8 );
|
|
|
|
else if( e->type == EXPR_SVAL )
|
|
|
|
HeapFree( GetProcessHeap(), 0, e->u.sval );
|
2004-03-20 20:18:46 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, e );
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_string_list( string_list *sl )
|
|
|
|
{
|
|
|
|
while( sl )
|
|
|
|
{
|
|
|
|
string_list *t = sl->next;
|
|
|
|
HeapFree( GetProcessHeap(), 0, sl->string );
|
|
|
|
HeapFree( GetProcessHeap(), 0, sl );
|
|
|
|
sl = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void delete_value_list( value_list *vl )
|
|
|
|
{
|
|
|
|
while( vl )
|
|
|
|
{
|
|
|
|
value_list *t = vl->next;
|
|
|
|
delete_expr( vl->val );
|
|
|
|
HeapFree( GetProcessHeap(), 0, vl );
|
|
|
|
vl = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-16 20:18:22 +01:00
|
|
|
static BOOL SQL_MarkPrimaryKeys( create_col_info *cols,
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *keys )
|
2004-03-16 20:18:22 +01:00
|
|
|
{
|
2004-03-20 20:18:46 +01:00
|
|
|
string_list *k;
|
2004-03-16 20:18:22 +01:00
|
|
|
BOOL found = TRUE;
|
|
|
|
|
|
|
|
for( k = keys; k && found; k = k->next )
|
|
|
|
{
|
|
|
|
create_col_info *c;
|
|
|
|
|
|
|
|
found = FALSE;
|
|
|
|
for( c = cols; c && !found; c = c->next )
|
|
|
|
{
|
|
|
|
if( lstrcmpW( k->string, c->colname ) )
|
|
|
|
continue;
|
|
|
|
c->type |= MSITYPE_KEY;
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT MSI_ParseSQL( MSIDATABASE *db, LPCWSTR command, MSIVIEW **phview )
|
|
|
|
{
|
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;
|
|
|
|
sql.view = phview;
|
|
|
|
|
2004-03-16 04:23:43 +01:00
|
|
|
r = SQL_parse(&sql);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("Parse returned %d\n", r);
|
|
|
|
if( r )
|
|
|
|
{
|
|
|
|
if( *sql.view )
|
|
|
|
(*sql.view)->ops->delete( *sql.view );
|
2004-06-26 02:18:23 +02:00
|
|
|
*sql.view = NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_BAD_QUERY_SYNTAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|