How to check if expression is Aggregate?

68 views
Skip to first unread message

Jurgis Pralgauskis

unread,
Dec 20, 2016, 5:00:02 AM12/20/16
to web2py-users
I have searchform,

where one can define various fields and mapping to expressions for comparison,
and it automatically constructs select query,

but if I want to check if expression is aggregate, and direct thesese queries to "having"

but if I try

if filter.target_expression.op == db._adapter.AGGREGATE:

I get

AttributeError: 'SQLite' object has no attribute 'AGGREGATE'




Anthony

unread,
Dec 20, 2016, 9:42:33 AM12/20/16
to web2py-users
How have you defined db? The _adapter attribute of a DAL instance should be a "SQLiteAdapter" object when using SQLite, not a "SQLite" object.

Anthony

Jurgis Pralgauskis

unread,
Dec 20, 2016, 4:03:27 PM12/20/16
to web...@googlegroups.com
it just has what  standar app gets:

    db = DAL(myconf.get('db.uri'),
             pool_size=myconf.get('db.pool_size'),
             migrate_enabled=myconf.get('db.migrate'),
             check_reserved=['all'])

@appconfig.ini

[db]
uri       = sqlite://storage.sqlite


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/0IvASrrIDkA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jurgis Pralgauskis
tel: 8-616 77613;
Don't worry, be happy and make things better ;)
http://galvosukykla.lt

Anthony

unread,
Dec 20, 2016, 5:22:46 PM12/20/16
to web2py-users
Not sure what's going on. You'll have to do some digging around. Maybe do a dir(db._adapter) to see what the object is.

Anthony


On Tuesday, December 20, 2016 at 4:03:27 PM UTC-5, Jurgis Pralgauskis wrote:
it just has what  standar app gets:

    db = DAL(myconf.get('db.uri'),
             pool_size=myconf.get('db.pool_size'),
             migrate_enabled=myconf.get('db.migrate'),
             check_reserved=['all'])

@appconfig.ini

[db]
uri       = sqlite://storage.sqlite

Jurgis Pralgauskis

unread,
Dec 21, 2016, 4:26:19 AM12/21/16
to web...@googlegroups.com
> dir(db._adapter)

 ['POOLS', 'REGEX_TABLE_DOT_FIELD', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_add_operators_to_parsed_row', '_add_reference_sets_to_parsed_row', '_after_connection', '_available_drivers', '_build_cursor', '_build_handlers_for_execution', '_build_joins_for_select', '_cached_select', '_clean_cursors', '_colexpand', '_connection_thname_', '_connection_uname_', '_count', '_cursors_thname_', '_cursors_uname_', '_delete', '_driver_from_uri', '_drop_table_cleanup', '_expand', '_expand_for_index', '_find_work_folder', '_geoexpand', '_get_or_build_free_cursor', '_initialize_', '_insert', '_load_dependencies', '_parse', '_parse_expand_colnames', '_pid_', '_regex_select_as_parser', '_register_extract', '_register_regexp', '_select', '_select_aux', '_select_aux_execute', '_select_wcols', '_update', 'adapt', 'adapter_args', 'after_connection', 'after_connection_hook', 'alias', 'bulk_insert', 'can_select_for_update', 'check_active_connection', 'close', 'close_all_instances', 'close_connection', 'close_cursor', 'commit', 'commit_on_alter_table', 'commit_prepared', 'common_filter', 'connection', 'connector', 'count', 'create_index', 'create_sequence_and_triggers', 'create_table', 'credential_decoder', 'cursor', 'cursors', 'db', 'db_codec', 'dbengine', 'dbpath', 'delete', 'dialect', 'distributed_transaction_begin', 'driver', 'driver_args', 'driver_name', 'drivers', 'drop', 'drop_index', 'drop_table', 'execute', 'execution_handlers', 'expand', 'expand_all', 'fetchall', 'fetchone', 'filter_sql_command', 'find_driver', 'folder', 'get_table', 'id_query', 'index_expander', 'insert', 'iterparse', 'iterselect', 'lastrowid', 'lock_cursor', 'migrator', 'parse', 'parse_value', 'parser', 'pool_size', 'prepare', 'reconnect', 'release_cursor', 'represent', 'representer', 'rollback', 'rollback_prepared', 'rowslice', 'select', 'set_folder', 'smart_adapt', 'sqlsafe_field', 'sqlsafe_table', 'support_distributed_transaction', 'table_alias', 'tables', 'test_connection', 'truncate', 'types', 'update', 'uploads_in_blob', 'uri', 'web2py_extract', 'web2py_regexp']

Anthony

unread,
Dec 21, 2016, 8:49:33 AM12/21/16
to web2py-users
That's odd. Hard to say what's going on without seeing the code. Maybe attach a minimal app that reproduces the problem.

Anthony


On Wednesday, December 21, 2016 at 4:26:19 AM UTC-5, Jurgis Pralgauskis wrote:
> dir(db._adapter)

 ['POOLS', 'REGEX_TABLE_DOT_FIELD', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_add_operators_to_parsed_row', '_add_reference_sets_to_parsed_row', '_after_connection', '_available_drivers', '_build_cursor', '_build_handlers_for_execution', '_build_joins_for_select', '_cached_select', '_clean_cursors', '_colexpand', '_connection_thname_', '_connection_uname_', '_count', '_cursors_thname_', '_cursors_uname_', '_delete', '_driver_from_uri', '_drop_table_cleanup', '_expand', '_expand_for_index', '_find_work_folder', '_geoexpand', '_get_or_build_free_cursor', '_initialize_', '_insert', '_load_dependencies', '_parse', '_parse_expand_colnames', '_pid_', '_regex_select_as_parser', '_register_extract', '_register_regexp', '_select', '_select_aux', '_select_aux_execute', '_select_wcols', '_update', 'adapt', 'adapter_args', 'after_connection', 'after_connection_hook', 'alias', 'bulk_insert', 'can_select_for_update', 'check_active_connection', 'close', 'close_all_instances', 'close_connection', 'close_cursor', 'commit', 'commit_on_alter_table', 'commit_prepared', 'common_filter', 'connection', 'connector', 'count', 'create_index', 'create_sequence_and_triggers', 'create_table', 'credential_decoder', 'cursor', 'cursors', 'db', 'db_codec', 'dbengine', 'dbpath', 'delete', 'dialect', 'distributed_transaction_begin', 'driver', 'driver_args', 'driver_name', 'drivers', 'drop', 'drop_index', 'drop_table', 'execute', 'execution_handlers', 'expand', 'expand_all', 'fetchall', 'fetchone', 'filter_sql_command', 'find_driver', 'folder', 'get_table', 'id_query', 'index_expander', 'insert', 'iterparse', 'iterselect', 'lastrowid', 'lock_cursor', 'migrator', 'parse', 'parse_value', 'parser', 'pool_size', 'prepare', 'reconnect', 'release_cursor', 'represent', 'representer', 'rollback', 'rollback_prepared', 'rowslice', 'select', 'set_folder', 'smart_adapt', 'sqlsafe_field', 'sqlsafe_table', 'support_distributed_transaction', 'table_alias', 'tables', 'test_connection', 'truncate', 'types', 'update', 'uploads_in_blob', 'uri', 'web2py_extract', 'web2py_regexp']

Jurgis Pralgauskis

unread,
Dec 21, 2016, 11:57:24 AM12/21/16
to web2py-users

> That's odd. Hard to say what's going on without seeing the code. Maybe attach a minimal app that reproduces the problem.

Anthony

unread,
Dec 21, 2016, 8:36:35 PM12/21/16
to web2py-users
What version of web2py, and are you sure it includes the proper version of PyDAL?

What is the object type of db._adapter (a) immediately after db is created in db.py and (b) when db is assigned from current.db in the module?

Your traceback shows object type "SQLite", but the adapter is not of that type.

Anthony

Jurgis Pralgauskis

unread,
Dec 23, 2016, 11:34:00 AM12/23/16
to web...@googlegroups.com
Hi,

I used git clone  from https://github.com/web2py/web2py.git -- that is probably problem
adapter always prints as:  <pydal.adapters.sqlite.SQLite object at 0x7fc701680450>

now I downloaded *_src.zip
and I get  <pydal.adapters.sqlite.SQLiteAdapter object at 0x7f30cea8f510>

Thanks, probably I shouldn't use git... (but thought would be easier to update to newest with pull..)


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/0IvASrrIDkA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Dec 23, 2016, 5:42:33 PM12/23/16
to web2py-users
On Friday, December 23, 2016 at 11:34:00 AM UTC-5, Jurgis Pralgauskis wrote:
Hi,

I used git clone  from https://github.com/web2py/web2py.git -- that is probably problem
adapter always prints as:  <pydal.adapters.sqlite.SQLite object at 0x7fc701680450>

PyDAL is now in a separate repository, so you have to do "git clone --recursive" to get the PyDAL.

Anthony

Jurgis Pralgauskis

unread,
Dec 23, 2016, 10:24:29 PM12/23/16
to web...@googlegroups.com
Yes, I did --recursive, as in description..

--

Anthony

unread,
Dec 24, 2016, 8:36:12 AM12/24/16
to web2py-users
On Friday, December 23, 2016 at 10:24:29 PM UTC-5, Jurgis Pralgauskis wrote:
Yes, I did --recursive, as in description..

Actually, it looks like the DAL has been refactored recently, so using the master branch, I think it would now be:

if filter.target_expression.op == db._adapter.dialect.aggregate:

Of course, this is not part of the public API -- you always risk backward compatibility issues when basing code on internal implementation details.

Anthony
Reply all
Reply to author
Forward
0 new messages