indra::util::named_query::NamedQuery Class Reference

List of all members.

Public Member Functions

def __init__
def name
def get_modtime
def load_contents
def delete
def ttl
def legacy_dbname
def return_as_map
def for_schema
def run
def sql
def refresh

Public Attributes

 deleted

Private Member Functions

def _reference_contents
def _convert_sql
def _prepare_like
def _build_around_key
def _build_append_key
def _prepare_integer
def _build_integer_key
def _strip_wildcards_to_list

Private Attributes

 _stat_interval_seconds
 _name
 _location
 _alternative
 _last_mod_time
 _last_check_time
 _contents
 _ttl
 _return_as_map
 _legacy_dbname
 _around
 _append
 _integer
 _options
 _base_query
 _query_suffix


Detailed Description

Definition at line 102 of file named_query.py.


Member Function Documentation

def indra::util::named_query::NamedQuery::__init__ (   self,
  name,
  filename 
)

Construct a NamedQuery object.  The name argument is an
arbitrary name as a handle for the query, and the filename is
a path to a file containing an llsd named query document.

Definition at line 103 of file named_query.py.

def indra::util::named_query::NamedQuery::name (   self  ) 

The name of the query. 

Definition at line 119 of file named_query.py.

def indra::util::named_query::NamedQuery::get_modtime (   self  ) 

Returns the mtime (last modified time) of the named query
file, if such exists.

Definition at line 123 of file named_query.py.

def indra::util::named_query::NamedQuery::load_contents (   self  ) 

Loads and parses the named query file into self.  Does
nothing if self.location is nonexistant.

Definition at line 130 of file named_query.py.

def indra::util::named_query::NamedQuery::_reference_contents (   self,
  contents 
) [private]

Definition at line 146 of file named_query.py.

def indra::util::named_query::NamedQuery::_convert_sql (   self,
  sql 
) [private]

convert the parsed sql into a useful internal structure.

This function has to turn the named query format into a pyformat
style. It also has to look for %:name% and :name% and
ready them for use in LIKE statements

Definition at line 177 of file named_query.py.

def indra::util::named_query::NamedQuery::_prepare_like (   self,
  match 
) [private]

This function changes LIKE statement replace behavior

It works by turning %:name% to %(_name_around)s and :name% to
%(_name_append)s. Since a leading '_' is not a valid keyname
input (enforced via unit tests), it will never clash with
existing keys. Then, when building the statement, the query
runner will generate corrected strings.

Definition at line 193 of file named_query.py.

def indra::util::named_query::NamedQuery::_build_around_key (   self,
  key 
) [private]

Definition at line 210 of file named_query.py.

def indra::util::named_query::NamedQuery::_build_append_key (   self,
  key 
) [private]

Definition at line 213 of file named_query.py.

def indra::util::named_query::NamedQuery::_prepare_integer (   self,
  match 
) [private]

This function adjusts the sql for #:name replacements

It works by turning #:name to %(_name_as_integer)s. Since a
leading '_' is not a valid keyname input (enforced via unit
tests), it will never clash with existing keys. Then, when
building the statement, the query runner will generate
corrected strings.

Definition at line 216 of file named_query.py.

def indra::util::named_query::NamedQuery::_build_integer_key (   self,
  key 
) [private]

Definition at line 227 of file named_query.py.

def indra::util::named_query::NamedQuery::_strip_wildcards_to_list (   self,
  value 
) [private]

Take string, and strip out the LIKE special characters.

Technically, this is database dependant, but postgresql and
mysql use the same wildcards, and I am not aware of a general
way to handle this. I think you need a sql statement of the
form:

LIKE_STRING( [ANY,ONE,str]... )

which would treat ANY as their any string, and ONE as their
single glyph, and str as something that needs database
specific encoding to not allow any % or _ to affect the query.

As it stands, I believe it's impossible to write a named query
style interface which uses like to search the entire space of
text available. Imagine the query:

% of brain used by average linden

In order to search for %, it must be escaped, so once you have
escaped the string to not do wildcard searches, and be escaped
for the database, and then prepended the wildcard you come
back with one of:

1) %\% of brain used by average linden
2) %%% of brain used by average linden

Then, when passed to the database to be escaped to be database
safe, you get back:

1) %\\% of brain used by average linden
: which means search for any character sequence, followed by a
  backslash, followed by any sequence, followed by ' of
  brain...'
2) %%% of brain used by average linden
: which (I believe) means search for a % followed by any
  character sequence followed by 'of brain...'

Neither of which is what we want!

So, we need a vendor (or extention) for LIKE_STRING. Anyone
want to write it?

Definition at line 230 of file named_query.py.

def indra::util::named_query::NamedQuery::delete (   self  ) 

Makes this query unusable by deleting all the members and
setting the deleted member.  This is desired when the on-disk
query has been deleted but the in-memory copy remains.

Definition at line 282 of file named_query.py.

def indra::util::named_query::NamedQuery::ttl (   self  ) 

Estimated time to live of this query. Used for web
services to set the Expires header.

Definition at line 293 of file named_query.py.

def indra::util::named_query::NamedQuery::legacy_dbname (   self  ) 

Definition at line 298 of file named_query.py.

def indra::util::named_query::NamedQuery::return_as_map (   self  ) 

Returns true if this query is configured to return its
results as a single map (as opposed to a list of maps, the
normal behavior).

Definition at line 301 of file named_query.py.

def indra::util::named_query::NamedQuery::for_schema (   self,
  db_name 
)

Definition at line 308 of file named_query.py.

def indra::util::named_query::NamedQuery::run (   self,
  connection,
  params,
  expect_rows = None,
  use_dictcursor = True 
)

given a connection, run a named query with the params

Note that this function will fetch ALL rows. We do this because it
opens and closes the cursor to generate the values, and this 
isn't a generator so the cursor has no life beyond the method call.

@param cursor The connection to use (this generates its own cursor for the query)
@param name The name of the query to run
@param params The parameters passed into the query
@param expect_rows The number of rows expected. Set to 1 if return_as_map is true.  Raises ExpectationFailed if the number of returned rows doesn't exactly match.  Kind of a hack.
@param use_dictcursor Set to false to use a normal cursor and manually convert the rows to dicts.
@return Returns the result set as a list of dicts, or, if the named query has return_as_map set to true, returns a single dict.

Definition at line 316 of file named_query.py.

def indra::util::named_query::NamedQuery::sql (   self,
  connection,
  params 
)

Generates an SQL statement from the named query document
and a dictionary of parameters.

Definition at line 373 of file named_query.py.

def indra::util::named_query::NamedQuery::refresh (   self  ) 

Refresh self from the file on the filesystem.

This is optimized to be callable as frequently as you wish,
without adding too much load.  It does so by only stat-ing the
file every N seconds, where N defaults to 5 and is
configurable through the member _stat_interval_seconds.  If the stat
reveals that the file has changed, refresh will re-parse the
contents of the file and use them to update the named query
instance.  If the stat reveals that the file has been deleted,
refresh will call self.delete to make the in-memory
representation unusable.

Definition at line 430 of file named_query.py.


Member Data Documentation

Definition at line 107 of file named_query.py.

Definition at line 108 of file named_query.py.

Definition at line 112 of file named_query.py.

Definition at line 113 of file named_query.py.

Definition at line 114 of file named_query.py.

Definition at line 115 of file named_query.py.

Definition at line 116 of file named_query.py.

Definition at line 148 of file named_query.py.

Definition at line 149 of file named_query.py.

Definition at line 150 of file named_query.py.

Definition at line 151 of file named_query.py.

Definition at line 156 of file named_query.py.

Definition at line 157 of file named_query.py.

Definition at line 158 of file named_query.py.

Definition at line 159 of file named_query.py.

Definition at line 173 of file named_query.py.

Definition at line 174 of file named_query.py.


The documentation for this class was generated from the following file:

Generated on Fri May 16 09:42:31 2008 for SecondLife by  doxygen 1.5.5