HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
SQLCriterions.py
Go to the documentation of this file.
1 '''
2 @package: dc
3 @author igor
4 @link: http://hierarchical-cluster-engine.com/
5 @copyright: Copyright © 2013-2014 IOIX Ukraine
6 @license: http://hierarchical-cluster-engine.com/license/
7 @since: 0.1
8 '''
9 
10 import dc_db.Constants as DB_CONST
11 
12 
13 CRITERION_WHERE = "WHERE"
14 CRITERION_ORDER = "ORDER BY"
15 CRITERION_LIMIT = "LIMIT"
16 
17 def generateCriterionSQL(criterions, additionWhere=None, siteId=None):
18  additionString = ""
19  if siteId is not None:
20  localCriterions = {}
21  for key in criterions:
22  if isinstance(criterions[key], basestring):
23  localCriterions[key] = criterions[key].replace("%" + DB_CONST.SITE_ID_NAME + "%", siteId)
24  else:
25  localCriterions[key] = criterions[key]
26  criterions = localCriterions
27 
28  # Criterions "WHERE" block
29  if CRITERION_WHERE in criterions and criterions[CRITERION_WHERE] is not None and criterions[CRITERION_WHERE] != "":
30  additionString += (" " + CRITERION_WHERE + " ")
31  if additionWhere is not None:
32  additionString += (additionWhere + " AND ")
33  additionString += str(criterions[CRITERION_WHERE])
34  elif additionWhere is not None:
35  additionString += (" " + CRITERION_WHERE + " ")
36  additionString += additionWhere
37  # Criterions "ORDER" block
38  if CRITERION_ORDER in criterions and criterions[CRITERION_ORDER] is not None and criterions[CRITERION_ORDER] != "":
39  additionString += (" " + CRITERION_ORDER + " ")
40  additionString += str(criterions[CRITERION_ORDER])
41  # Criterions "LIMIT" block
42  if CRITERION_LIMIT in criterions and criterions[CRITERION_LIMIT] is not None and criterions[CRITERION_LIMIT] != "":
43  localLimit = criterions[CRITERION_LIMIT]
44  if isinstance(localLimit, list):
45  localString = ("%s , %s" % (str(localLimit[0]), str(localLimit[1])))
46  else:
47  localString = str(localLimit)
48  additionString += (" " + CRITERION_LIMIT + " " + localString)
49  return additionString
def generateCriterionSQL(criterions, additionWhere=None, siteId=None)