Re: Extending SQL a bit

Tobias Downer <[email protected]> Thu, 24 Feb 2005 14:36:42 -0800
Newsgroups gmane.comp.db.mckoi
Message-ID <[email protected]>
As well as changing the grammar rules, you will also need to add the 
appropriate behaviour in com/mckoi/database/interpret/Insert.java to 
handle the information.

Your grammar should probably look something like,

   Expression time_exp = null;
   ...
      (   [ "(" BasicColumnList(col_list) ")" ]
             (   <VALUES> InsertDataList(data_list)
                     { type = "from_values"; }
               | select = Select()
                     { type = "from_select"; }
             )
         | <SET> AssignmentList(assignments) { type = "from_set"; }
      )
      [ <EXPIRES> <ASSIGNMENT> time_exp = DoExpression()
                     { cmd.putObject("expires", timp_exp); } ]

This will create an 'expires' entry in the cmd object if the expires 
assignment is optionally given.  The expires object will be an Expression.

In com/mckoi/database/interpret/Insert.java, you would evaluate the 
expires expression if it's present and insert the data into your hidden 
column.

Hope that helps,
Toby.

Kim Schulz wrote:
> Hi
> I'm working on an experimental project where I need to extend the SQL
> language with an expiry time for inserts. 
> 
> Bacically I want to do the Following:
> 
> INSERT INTO table SET (a=1,b=2,c=3) EXPIRES=NOW()+1000;
> 
> the EXPIRES part is actually an "alias" for doing somthing like
>  
> INSERT INTO table SET (a=1,b=2,c=3,expTime=NOW()+1000);
> 
> expTime is a hidden column I have in all tables (for now) .
> 
> I'm trying to get the SQL.jj file to recognize this, but I'm used to
> SableCC so the syntax is quite different for me. 
> 
> I have added 
> 
> |<EXPIRES: "expires"> to the tokens and changed the Statement Tree for
> Insert to be:
> StatementTree Insert() :
> { 
> StatementTree cmd =
> newStatementTree("com.mckoi.database.interpret.Insert"); 
> String table_name;   
> ArrayList col_list = new ArrayList();
> ArrayList data_list = new ArrayList(); // ( Array of Expression[] )
> StatementTree select = null;
> ArrayList assignments = new ArrayList();
> String type;
> }
> {
> 
>   ( <INSERT> [ <INTO> ] table_name = TableName()
>     (   [ "(" BasicColumnList(col_list) ")" ]
>            (   <VALUES> InsertDataList(data_list)  { type =
> "from_values"; }             | select = Select()                   {
> type = "from_select"; }           )
> 	   | <SET> AssignmentList(assignments) { type = "from_set"; }
>      )
>            | <EXPIRES> <ASSIGNMENT> ExpireTime(exp_time) {expires =
> "expires";}
> )
>   { cmd.putObject("table_name", table_name);
>     cmd.putObject("col_list", col_list);
>     cmd.putObject("data_list", data_list);
>     cmd.putObject("select", select);
>     cmd.putObject("assignments", assignments);
>     cmd.putObject("exp_time",exp_time);
>     cmd.putObject("expires",expires);
>     cmd.putObject("type", type);
>     return cmd; }
> }
> 
> 
> I want the RHS of the assignment to be evaluated completly (like the
> NOW()+1000 part) and then saved in the tree (to be added to the table
> later). But this is where I'm stuck at the moment. I'm not sure how to
> create this method. Can anyone help me out with this?
> 
> 
> 
> 
> 
> 



---------------------------------------------------------------
Mckoi SQL Database mailing list  http://www.mckoi.com/database/
To unsubscribe, send a message to [email protected]