RicardoSQLiteOddity: ErrorSQLite.txt

File ErrorSQLite.txt, 2.8 kB (added by raraoz, 3 years ago)
Line 
1 ci = dabo.db.dConnectInfo(DbType='SQLite')
2 ci.Database = 'MultiMenu.db'
3 conn = dabo.db.dConnection(ci)
4 crsr = conn.getDaboCursor()
5 menu = 'Hijo'
6
7 crsr.execute('select Name '
8              'from menu '
9              'inner join path '
10                  'on path.Id = menu.MenuId '
11              'group by path.Id '
12              'having count(*) = 1')    # get the
13 children of root
14 crsr.getDataSet()
15
16 <Output>  ({'Name': u'Hijo'}, {'Name': u'OtroHijo'}) </Output>
17 <Comment> This is ok </Comment>
18
19  crsr.execute('select menu.Name '
20               'from menu '
21               'inner join path '
22                   'on path.Id = menu.MenuId '
23               'group by path.Id '
24               'having count(*) = 1')    # get the children of root
25 crsr.getDataSet()
26
27 <Output>  ({'menu.Name': u'Hijo'}, {'menu.Name': u'OtroHijo'}) </Output>
28 <Comment> This is ok (notice now it is "menu.Name"
29                       instead of "Name") </Comment>
30
31 crsr.execute('select distinct menu.Name '
32              'from menu '
33              'inner join path '
34                 'on path.Id = menu.MenuId '
35              'group by path.Id '
36              'having count(*) = 1')    # get the children of root
37 crsr.getDataSet()
38
39 <Output>  ({'menu.Name': u'Hijo'}, {'menu.Name': u'OtroHijo'}) </Output>
40 <Comment> This is ok (with "distinct" I still get the
41           same result "menu.Name") (1) </Comment>
42
43 crsr.execute("select distinct menu.Name "
44              "from menu "
45              "inner join path "
46                 "on path.Id = menu.MenuId "
47              "left join (select MenuId as 'pId' "
48                         "from menu "
49                         "where name = '" + menu + "') Parent "
50              "where Id in (select Id "
51                           "from path "
52                           "where AncestorId = Parent.pId) "
53                                  "and Id not in "
54                                       "(select Id "
55                                        "from path "
56                                        "where Id in(select Id "
57                                                     "from path "
58                                                    "where AncestorId =
59 Parent.pId) "
60                                  "and AncestorId not in "
61                                       "(select AncestorId "
62                                        "from path "
63                                        "where Id = Parent.pId) "
64                                  "and AncestorId != Parent.pId) ")
65 crsr.getDataSet()
66
67 <Output>  ({'Name': u'Hijo-1'}, {'Name': u'Hijo-2'}) </Output>
68 <Comment> Ooops!!! Here I'm using "select distinct menu.name" in the
69           main select
70           as in the previous query (1) but I'm getting "Name" as key
71           instead of "menu.Name".
72           This is the inconsistency I was talking about.
73 </Comment>