home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
sybase
/
starbuck
/
hpp.z
/
wsqlstmt.hpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-21
|
9KB
|
253 lines
#ifndef _WSQLSTMT_HPP_INCLUDED
#define _WSQLSTMT_HPP_INCLUDED
#ifndef _WSQLCONN_HPP_INCLUDED
#include "wsqlconn.hpp"
#endif
class WSQLCorrelation : public WObject
{
WDeclareSubclass( WSQLCorrelation, WObject );
public:
WString owner;
WString name;
WString correlation;
};
class WSQLColumnExpr : public WString
{
WDeclareSubclass( WSQLColumnExpr , WString);
public:
WSQLColumnExpr( WString name, WString as = WString( "" ) );
WBool computed;
WString as;
};
class WSQLTableExpr : public WSQLCorrelation {
WDeclareSubclass( WSQLTableExpr, WSQLCorrelation );
public:
WVector< WSQLColumnExpr > columns;
};
class WSQLWhereExpr : public WObject {
WDeclareSubclass( WSQLWhereExpr, WObject );
public:
WString expr1;
WString op;
WString expr2;
WString condition;
WBool exclusive;
};
class WSQLHaveExpr : public WSQLWhereExpr {
WDeclareSubclass( WSQLHaveExpr, WSQLWhereExpr );
};
class WSQLGroupExpr : public WString {
WDeclareSubclass( WSQLGroupExpr, WString );
};
class WSQLJoinExpr : public WObject {
WDeclareSubclass( WSQLJoinExpr, WObject );
public:
WString type;
WString table1;
WString correlation1;
WString table2;
WString correlation2;
int tab1;
int tab2;
WVector< WString > how; // array of join conditions
};
class WSQLOrderExpr : public WObject {
WDeclareSubclass( WSQLOrderExpr, WObject );
public:
WString expr;
int ascending;
};
extern template WVector< WSQLColumnExpr >;
extern template WVector< WSQLTableExpr >;
extern template WVector< WSQLWhereExpr >;
extern template WVector< WSQLHaveExpr >;
extern template WVector< WSQLJoinExpr >;
extern template WVector< WSQLGroupExpr >;
extern template WVector< WSQLOrderExpr >;
extern template WVector< WSQLCorrelation >;
class WCMCLASS WSQLStatement : public WObject {
WDeclareSubclass( WSQLStatement, WObject );
struct WSQLToken {
int blanks;
WString text;
};
public:
WSQLStatement()
: col_expr( TRUE )
, tab_expr( TRUE )
, whr_expr( TRUE )
, hav_expr( TRUE )
, joins( TRUE )
, grp_expr( TRUE )
, ord_expr( TRUE )
, _quote_names( TRUE )
, _use_owner( TRUE )
, _auto_refresh( TRUE )
{}
/***********************************************************
* Properties
***********************************************************/
WBool GetQuoteNames() { return( _quote_names ); }
void SetQuoteNames( WBool quote ) { _quote_names = quote; }
WBool GetUseOwner() { return( _use_owner ); }
void SetUseOwner( WBool owner ) { _use_owner = owner; }
WBool GetAutoRefresh() { return( _auto_refresh ); }
void SetAutoRefresh( WBool autoref ) { _auto_refresh = autoref; }
WBool GetDistinct() { return( _distinct ); }
void SetDistinct( WBool distinct ) { _distinct = distinct; }
/***********************************************************
* Methods
***********************************************************/
WString Parse( WString statement , WSQLConnection *conn = NULL);
WString Compose();
int NumColumns();
WString Column( int i );
void AddColumn( WString const & );
void DeleteColumns();
int NumComputed();
WString Computed( int i );
void DeleteComputed();
WSQLTableExpr *Table( int i ) { return( tab_expr[i] ); }
int NumTables() { return( tab_expr.Count() ); }
void DeleteTables();
void AddTable( WString const &owner, WString const &name );
WSQLWhereExpr *Where( int i ) { return( whr_expr[i] ); }
int NumWheres() { return( whr_expr.Count() ); }
void DeleteWheres();
void AddWhere( WString const &expr, WString const &condition, WBool excl = FALSE );
WSQLHaveExpr *Have( int i ) { return( hav_expr[i] ); }
int NumHaves() { return( hav_expr.Count() ); }
void DeleteHaves();
void AddHave( WString const &, WString const &condition );
WSQLJoinExpr *Join( int i ) { return( joins[i] ); }
int NumJoins() { return( joins.Count() ); }
void DeleteJoins();
void AddJoin( WString const &tab1, WString const &tab2, WString const &type );
WSQLGroupExpr *Group( int i ) { return( grp_expr[i] ); }
int NumGroups() { return( grp_expr.Count() ); }
void DeleteGroups();
void AddGroup( WString const & );
WSQLOrderExpr *Order( int i ) { return( ord_expr[i] ); }
int NumOrders() { return( ord_expr.Count() ); }
void DeleteOrders();
void AddOrder( WString const &, int );
int NumJoinConds( int i ) { return( joins[i]->how.Count() ); }
WString JoinCond( int i, int j ) { return( *(joins[i]->how[j]) ); }
void DeleteJoinConds( int i );
void AddJoinCond( int i, WString const &condition );
void ParseDot( WString , WString &, WString & );
WBool ParseJoinCond( WString const &str, WVector<WString> &list );
void Update();
private:
WBool _distinct;
WVector< WSQLColumnExpr > col_expr;
WVector< WSQLTableExpr > tab_expr;
WVector< WSQLWhereExpr > whr_expr;
WVector< WSQLHaveExpr > hav_expr;
WVector< WSQLJoinExpr > joins;
WVector< WSQLGroupExpr > grp_expr;
WVector< WSQLOrderExpr > ord_expr;
WVector< WSQLCorrelation > correlations;
// parser functions
void save_parse( WString const &expr );
void restore_parse();
void parse_as( WString const &expr, WString &name, WString &as );
WBool get_quoted_token( WWidestChar quote );
void get_numeric_token( void );
void get_identifier( void );
void get_token( void );
WBool in_keyword_range( WString token, int kw_1, int kw_2 );
WString add_token( WString str );
WString parse_expr( WBool stop_on_comma, WBool stop_on_bool, int kw_1, int kw_2 );
WBool parse_select( void );
int add_table( WString expr );
WBool parse_from( void );
WBool parse_where( void );
WBool parse_group();
WBool parse_having();
WBool parse_order();
WBool is_operator( WString p, int *op_len );
void fix_table_exprs();
void fix_where_expr( WSQLWhereExpr *exp );
void fix_correlations();
void fix_tables();
void fix_where_exprs( WVector< WSQLWhereExpr > &exp );
void fix_have_exprs( WVector< WSQLHaveExpr > &exp );
// parser data
WString _str;
WULong _bufidx;
char const *_bufptr;
WSQLToken _token;
WString _saveStr;
WULong _saveBufidx;
char const *_saveBufptr;
WSQLToken _saveToken;
WString _errormsg;
// compose functions
WString quote( WString const &str, WChar quote_char = '"' );
WString build_select();
WString build_from();
WString build_orderby();
WString build_where();
WString build_groupby();
WString build_having();
WString substitute_correlation_names( WString info );
WString Translate( WString x ) { return( x ); }
int get_table_index( WString info );
int get_column_index( WString expr );
// compose data
WBool _quote_names;
WBool _use_owner;
WBool _auto_refresh;
WSQLConnection *_connection;
};
extern WBool ParseSQL( WString, WSQLStatement *, WString * );
#if 0
extern char *ParseWhere( char * );
extern void ParseColName( char *, unsigned, char *, unsigned );
extern void FreeParse( WSQLStatement * );
#endif
#endif