本文整理汇总了Python中Cheetah.Template.Template.functionHeader方法的典型用法代码示例。如果您正苦于以下问题:Python Template.functionHeader方法的具体用法?Python Template.functionHeader怎么用?Python Template.functionHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cheetah.Template.Template
的用法示例。
在下文中一共展示了Template.functionHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeNextFreeFunc
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import functionHeader [as 别名]
def makeNextFreeFunc( table, var ):
"""
Make a function that finds the next highest value of
an integer field; used to auto-increment inserts for integer parts of a primary key
"""
template = Template( file=templatesPath()+"get_next_free.func.tmpl" )
template.functionHeader = makeNextFreeHeader( var, CONNECTION_STRING, ' is' )
template.statement = "select coalesce( max( "+var.varname+" ) + 1, 1 ) from "+table.qualifiedName()
template.functionName = "Next_Free_"+var.adaName
template.adaName = var.adaName
template.default = var.getDefaultAdaValue()
template.adaType = var.getAdaType( True )
template.getFunction = makeValueFunction( var, "0", "0" )
return str( template );
示例2: makeNextFreeFunc
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import functionHeader [as 别名]
def makeNextFreeFunc( table, var ):
"""
Make a function that finds the next highest value of
an integer field; used to auto-increment inserts for integer parts of a primary key
"""
template = Template( file=templatesPath()+"get_next_free.func.tmpl" )
template.functionHeader = makeNextFreeHeader( var, CONNECTION_STRING, ' is' )
template.statement = "select max( "+var.varname+" ) from "+table.qualifiedName()
template.functionName = "Next_Free_"+var.adaName
template.adaName = var.adaName
template.adaType = var.getAdaType( True )
template.default = var.getDefaultAdaValue()
if( var.sqlType == 'BIGINT' ):
template.whichBinding = 'L'
else:
template.whichBinding = 'I'
s = str(template)
return s
示例3: makeRetrieveSFunc
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import functionHeader [as 别名]
def makeRetrieveSFunc( table, database ):
"""
table - Table class from table_model.py
database - complete enclosuing Database model from table_model.py
Make a fuction that, for a given table (say 'fred'), takes an sql string as input (just the query part)
and returns a single
list of fred records (fred_list, as declared in the main database declarations ads file).
This version has wide_string handling jammed off
Structure is:
- declare local versions of all fred's variables
- declare aliases (pointers) to these variables, where needed
- declare length holders for each one
- make the query by appending the query part to a constant 'select part'
- prepare the query
- bind variables/aliase
- execute
- loop round, map the locals to one record
-- add the variable to the collection
There's a certain amount of trial an error in this..
"""
instanceName = table.makeName( Format.ada, Qualification.unqualified, ItemType.instanceName )
outputRecord = table.makeName( Format.ada, Qualification.full, ItemType.table )
template = Template( file=templatesPath()+"retrieve_wstr.func.tmpl" )
template.functionHeader = makeRetrieveSHeader( table, CONNECTION_STRING, ' is' )
template.listType = table.makeName( Format.ada, Qualification.full, ItemType.alist )
template.addToMap = "l.append( "+ instanceName +" )"
template.bindings = []
template.adaInstanceName = instanceName
template.variableDecl = instanceName + " : " + outputRecord
template.adaQualifiedOutputRecord = outputRecord
pos = 0
for var in table.variables:
binding = makeBinding( database.databaseAdapter, instanceName, var, pos )
pos += 1
template.bindings.append( binding )
s = str(template)
return s
示例4: makeRetrieveSFunc
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import functionHeader [as 别名]
def makeRetrieveSFunc( table, database ):
"""
table - Table class from table_model.py
database - complete enclosuing Database model from table_model.py
Make a fuction that, for a given table (say 'fred'), takes an sql string as input (just the query part)
and returns a single
list of fred records (fred_list, as declared in the main database declarations ads file).
This version has wide_string handling jammed off
Structure is:
- declare local versions of all fred's variables
- declare aliases (pointers) to these variables, where needed
- declare length holders for each one
- make the query by appending the query part to a constant 'select part'
- prepare the query
- bind variables/aliase
- execute
- loop round, map the locals to one record
-- add the variable to the collection
There's a certain amount of trial an error in this..
"""
template = Template( file=templatesPath()+"retrieve_wstr.func.tmpl" )
template.functionHeader = makeRetrieveSHeader( table, CONNECTION_STRING, ' is' )
template.listType = table.adaQualifiedListName
template.variableDecl = table.adaInstanceName + " : " + table.adaQualifiedOutputRecord
template.addToMap = table.adaQualifiedContainerName+".append( l, "+ table.adaInstanceName +" )"
template.aliasDeclarations = []
template.pointers = []
template.lenDeclarations = []
template.mappingsFromAliasToRecord = []
template.bindings = []
pos = 0
for var in table.variables:
pos += 1
alias = var.adaName + ": aliased " + var.odbcType;
if( var.isStringType() ):
isize = int(var.size);
string_padd = '@' * isize
alias += " := " + makePaddedString( 4, string_padd, isize )
template.aliasDeclarations.append( alias );
len_decl = var.adaName + "_len : aliased SQLLEN := " + var.adaName+"'Size";
template.lenDeclarations.append( len_decl )
binding = makeBinding( database.databaseAdapter, var, pos )
template.bindings.append( binding )
if( var.isRealOrDecimalType() or var.isDateType() or var.isStringType() ): ## NOTE: is String type is only because we're trying wide_strings here, otherwise
if( var.isRealOrDecimalType() ): ## there's a simple SQLBind version that doens't need any of this
pointer = var.adaName + "_access : Real_Access := "+var.adaName+"'access"
mapping = table.adaInstanceName + "." + var.adaName + ":= " + var.adaType + "( "+var.adaName + "_access.all )"
elif( var.isDateType()):
pointer = var.adaName + "_access : Timestamp_Access := "+var.adaName+"'access"
mapping = table.adaInstanceName + "." + var.adaName + ":= dodbc.Timestamp_To_Ada_Time( "+var.adaName + "_access.all )"
if( var.isStringType() ):
mapping = table.adaInstanceName + "." + var.adaName + " := Slice_To_Unbounded( " + var.adaName + ", 1, Natural( "+var.adaName+"_len ) )"
pointer = var.adaName + "_access : String_Access := "+var.adaName+"'access"
template.pointers.append( pointer )
else: ## integer/enum types
if( var.schemaType == 'ENUM' ):
mapping = table.adaInstanceName + "." + var.adaName + " := "+ var.adaType+"'Val( " + var.adaName + " )"
elif( var.schemaType == 'BOOLEAN' ):
mapping = table.adaInstanceName + "." + var.adaName + " := Boolean'Val( " + var.adaName + " )"
else:
mapping = table.adaInstanceName + "." + var.adaName + " := " + var.adaName
template.mappingsFromAliasToRecord.append( mapping )
s = str(template)
return s