Commit d16316f9 authored by Jerry Ajay's avatar Jerry Ajay

Enhanced Logic.

parent 7ae76dc9
......@@ -5,6 +5,7 @@
# definition at http://www.sqlite.org/lang_select.html
#
from pyparsing import *
import cProfile, pstats, StringIO
LPAR,RPAR,COMMA = map(Suppress,"(),")
select_stmt = Forward().setName("select statement")
......@@ -49,7 +50,7 @@ string_literal = QuotedString("'")
blob_literal = Combine(oneOf("x X") + "'" + Word(hexnums) + "'")
table_entry = ( table_name + "." + column_name |
table_name + "." + "*" )
literal_value = ( string_literal | numeric_literal | table_entry |
literal_value = ~keyword + ( string_literal | numeric_literal | table_entry |
blob_literal | NULL | CURRENT_TIME | CURRENT_DATE | CURRENT_TIMESTAMP )
bind_parameter = (
Word("?",nums) |
......@@ -57,24 +58,24 @@ bind_parameter = (
)
type_name = oneOf("TEXT REAL INTEGER BLOB NULL")
#SELECT GROUP_CONCAT(CASE WHEN groupConcatSourceTable.is_checked IS NULL THEN '0' ELSE (REPLACE(REPLACE(groupConcatSourceTable.is_checked,':','::'),'\/','\/\/')) END || ' : ' || CASE WHEN groupConcatSourceTable.text IS NULL THEN '' ELSE (REPLACE(REPLACE(groupConcatSourceTable.text,':','::'),'\/','\/\/')) END, ' \/ ') FROM (SELECT grpConcatListItemTable.is_checked, grpConcatListItemTable.text, CASE tree_entity.is_graveyard_off WHEN 1 THEN 0 ELSE grpConcatListItemTable.is_checked END AS first_order FROM list_item AS grpConcatListItemTable WHERE grpConcatListItemTable.list_parent_id=tree_entity._id AND grpConcatListItemTable.is_deleted=0 ORDER BY first_order ASC,grpConcatListItemTable.order_in_parent DESC,grpConcatListItemTable.time_last_updated DESC LIMIT 7 ) AS groupConcatSourceTable""".splitlines()
#SELECT GROUP_CONCAT( CASE WHEN groupConcatSourceTable.is_checked IS NULL THEN '0' END ) FROM (SELECT grpConcatListItemTable.is_checked, grpConcatListItemTable.text, CASE tree_entity.is_graveyard_off WHEN 1 THEN 0 ELSE grpConcatListItemTable.is_checked END AS first_order FROM list_item AS grpConcatListItemTable WHERE grpConcatListItemTable.list_parent_id=tree_entity._id AND grpConcatListItemTable.is_deleted=0 ORDER BY first_order ASC,grpConcatListItemTable.order_in_parent DESC,grpConcatListItemTable.time_last_updated DESC LIMIT 7 ) AS groupConcatSourceTable""".splitlines()
expr_term = (
CASE + Optional(literal_value) + OneOrMore(WHEN + literal_value + THEN + literal_value) + Optional(ELSE + literal_value) + END |
expr_term = Forward()
case_entry = (CASE + Optional(expr_term) + OneOrMore(WHEN + delimitedList(expr_term | expr) + THEN + expr_term) + Optional(ELSE + expr_term) + END)
expr_term << (
CAST + LPAR + expr + AS + type_name + RPAR |
EXISTS + LPAR + select_stmt + RPAR |
function_name + LPAR + literal_value + COMMA + literal_value + RPAR |
function_name + LPAR + Optional(delimitedList(string_literal) | "*" | delimitedList(expr)) + RPAR |
function_name + LPAR + Optional("*" | delimitedList(expr_term) | delimitedList(expr)) + RPAR |
case_entry |
literal_value |
bind_parameter |
identifier
)
UNARY,BINARY,TERNARY=1,2,3
expr << operatorPrecedence(expr_term,
expr << (operatorPrecedence(expr_term,
[
(oneOf('- + ~') | NOT, UNARY, opAssoc.LEFT),
('||', BINARY, opAssoc.LEFT),
(oneOf('* / %'), BINARY, opAssoc.LEFT),
(oneOf('+ -'), BINARY, opAssoc.LEFT),
(oneOf('<< >> & |'), BINARY, opAssoc.LEFT),
......@@ -83,7 +84,7 @@ expr << operatorPrecedence(expr_term,
('||', BINARY, opAssoc.LEFT),
(AND , BINARY, opAssoc.LEFT),
((BETWEEN,AND), TERNARY, opAssoc.LEFT),
])
]) | expr_term)
compound_operator = (UNION + Optional(ALL) | INTERSECT | EXCEPT)
......@@ -115,7 +116,7 @@ select_stmt << (select_core + ZeroOrMore(compound_operator + select_core) +
tests ="""
SELECT GROUP_CONCAT('sadfa', 'dsfsaf') FROM (SELECT grpConcatListItemTable.is_checked, grpConcatListItemTable.text, CASE tree_entity.is_graveyard_off WHEN 1 THEN 0 ELSE grpConcatListItemTable.is_checked END AS first_order FROM list_item AS grpConcatListItemTable WHERE grpConcatListItemTable.list_parent_id=tree_entity._id AND grpConcatListItemTable.is_deleted=0 ORDER BY first_order ASC,grpConcatListItemTable.order_in_parent DESC,grpConcatListItemTable.time_last_updated DESC LIMIT 7 ) AS groupConcatSourceTable""".splitlines()
SELECT GROUP_CONCAT( CASE WHEN groupConcatSourceTable.is_checked IS NULL THEN '0' END ) FROM (SELECT grpConcatListItemTable.is_checked, grpConcatListItemTable.text, CASE tree_entity.is_graveyard_off WHEN 1 THEN 0 ELSE grpConcatListItemTable.is_checked END AS first_order FROM list_item AS grpConcatListItemTable WHERE grpConcatListItemTable.list_parent_id=tree_entity._id AND grpConcatListItemTable.is_deleted=0 ORDER BY first_order ASC,grpConcatListItemTable.order_in_parent DESC,grpConcatListItemTable.time_last_updated DESC LIMIT 7 ) AS groupConcatSourceTable""".splitlines()
#SELECT GROUP_CONCAT(CASE WHEN groupConcatSourceTable.is_checked IS NULL THEN '0' ELSE (REPLACE(REPLACE(groupConcatSourceTable.is_checked,':','::'),'\/','\/\/')) END || ' : ' || CASE WHEN groupConcatSourceTable.text IS NULL THEN '' ELSE (REPLACE(REPLACE(groupConcatSourceTable.text,':','::'),'\/','\/\/')) END, ' \/ ') FROM (SELECT grpConcatListItemTable.is_checked, grpConcatListItemTable.text, CASE tree_entity.is_graveyard_off WHEN 1 THEN 0 ELSE grpConcatListItemTable.is_checked END AS first_order FROM list_item AS grpConcatListItemTable WHERE grpConcatListItemTable.list_parent_id=tree_entity._id AND grpConcatListItemTable.is_deleted=0 ORDER BY first_order ASC,grpConcatListItemTable.order_in_parent DESC,grpConcatListItemTable.time_last_updated DESC LIMIT 7 ) AS groupConcatSourceTable""".splitlines()
#SELECT tree_entity._id, tree_entity.uuid, tree_entity.type, tree_entity.title, tree_entity.color_name, tree_entity.is_graveyard_off, tree_entity.is_graveyard_closed, tree_entity.is_new_list_item_from_top, tree_entity.parent_id, tree_entity.order_in_parent, tree_entity.is_archived, tree_entity.is_trashed, (SELECT GROUP_CONCAT(imagesGroupConcatSourceTable._id, ' \/ ') FROM (SELECT imagesGroupConcatBlobsTable._id FROM blob_node AS imagesGroupConcatBlobsTable WHERE imagesGroupConcatBlobsTable.tree_entity_id=tree_entity._id AND imagesGroupConcatBlobsTable.type=0 AND imagesGroupConcatBlobsTable.is_deleted=0 ORDER BY imagesGroupConcatBlobsTable.time_created DESC LIMIT 6) AS imagesGroupConcatSourceTable), (SELECT COUNT(*) FROM blob_node AS blobCountTable WHERE tree_entity._id=blobCountTable.tree_entity_id AND blobCountTable.is_deleted=0 AND blobCountTable.type=0), (SELECT COUNT(*) FROM blob_node AS blobCountTable WHERE tree_entity._id=blobCountTable.tree_entity_id AND blobCountTable.is_deleted=0 AND blobCountTable.type=1), (SELECT GROUP_CONCAT(CASE WHEN groupConcatSourceTable.is_checked IS NULL THEN '0' ELSE (REPLACE(REPLACE(groupConcatSourceTable.is_checked,':','::'),'\/','\/\/')) END || ' : ' || CASE WHEN groupConcatSourceTable.text IS NULL THEN '' ELSE (REPLACE(REPLACE(groupConcatSourceTable.text,':','::'),'\/','\/\/')) END, ' \/ ') FROM (SELECT grpConcatListItemTable.is_checked, grpConcatListItemTable.text, CASE tree_entity.is_graveyard_off WHEN 1 THEN 0 ELSE grpConcatListItemTable.is_checked END AS first_order FROM list_item AS grpConcatListItemTable WHERE grpConcatListItemTable.list_parent_id=tree_entity._id AND grpConcatListItemTable.is_deleted=0 ORDER BY first_order ASC,grpConcatListItemTable.order_in_parent DESC,grpConcatListItemTable.time_last_updated DESC LIMIT 7 ) AS groupConcatSourceTable), reminder.reminder_type, reminder.reminder_state, reminder.julian_day, reminder.time_of_day, reminder.time_period, reminder.location_type, reminder.location_name, reminder.longitude, reminder.latitude, reminder.radius, reminder.location_address, reminder.location_reference, tree_entity.account_id, alert.state, (SELECT COUNT(1) FROM list_item_conflict WHERE tree_entity._id=list_item_conflict.list_parent_id), tree_entity.version, tree_entity.is_owner, tree_entity.has_read, tree_entity.sharer_email, (SELECT COUNT(1) FROM sharing WHERE tree_entity._id=sharing.tree_entity_id AND sharing.is_deleted=0), (SELECT GROUP_CONCAT(CASE WHEN shareesGroupConcatSourceTable.email IS NULL THEN '' ELSE (REPLACE(REPLACE(shareesGroupConcatSourceTable.email,':','::'),'\/','\/\/')) END || ' : ' || CASE WHEN shareesGroupConcatSourceTable.name IS NULL THEN '' ELSE (REPLACE(REPLACE(shareesGroupConcatSourceTable.name,':','::'),'\/','\/\/')) END || ' : ' || shareesGroupConcatSourceTable.role || ' : ' || CASE WHEN shareesGroupConcatSourceTable.avatar_uri IS NULL THEN '' ELSE (REPLACE(REPLACE(shareesGroupConcatSourceTable.avatar_uri,':','::'),'\/','\/\/')) END, ' \/ ') FROM (SELECT shareesGroupConcatTable.email, shareesGroupConcatTable.name, shareesGroupConcatTable.role, shareesGroupConcatTable.avatar_uri FROM sharing AS shareesGroupConcatTable WHERE shareesGroupConcatTable.tree_entity_id=tree_entity._id AND shareesGroupConcatTable.is_deleted=0 ) AS shareesGroupConcatSourceTable), tree_entity.last_modifier_email, tree_entity.last_changes_seen_timestamp, tree_entity.shared_timestamp, tree_entity.user_edited_timestamp FROM tree_entity LEFT OUTER JOIN reminder ON (tree_entity._id=reminder.tree_entity_id AND reminder.is_deleted=0) LEFT OUTER JOIN alert ON (alert.reminder_id=reminder._id) WHERE ((tree_entity.is_deleted=0) AND (tree_entity._id IN () AND is_trashed=0)) GROUP BY tree_entity._id""".splitlines()
#select * from xyzzy where z > 100
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment