コード例 #1
0
ファイル: waterlevel2.py プロジェクト: rolker/noaadata
def sqlInsert(params, extraParams=None, dbType="postgres"):
    """
        Give the SQL INSERT statement
        @param params: dict keyed by field name of values
        @param extraParams: any extra fields that you have created beyond the normal ais message fields
        @rtype: sqlhelp.insert
        @return: insert class instance
         TODO(schwehr):allow optional type checking of params?
        @warning: this will take invalid keys happily and do what???
        """

    i = sqlhelp.insert("waterlevel", dbType=dbType)

    if dbType == "postgres":
        finished = []
        for key in params:
            if key in finished:
                continue

            if key not in toPgFields and key not in fromPgFields:
                if type(params[key]) == Decimal:
                    i.add(key, float(params[key]))
                else:
                    i.add(key, params[key])
            else:
                if key in fromPgFields:
                    val = params[key]
                    # Had better be a WKT type like POINT(-88.1 30.321)
                    i.addPostGIS(key, val)
                    finished.append(key)
                else:
                    # Need to construct the type.
                    pgName = toPgFields[key]
                    # valStr='GeomFromText(\''+pgTypes[pgName]+'('
                    valStr = pgTypes[pgName] + "("
                    vals = []
                    for nonPgKey in fromPgFields[pgName]:
                        vals.append(str(params[nonPgKey]))
                        finished.append(nonPgKey)
                    valStr += " ".join(vals) + ")"
                    i.addPostGIS(pgName, valStr)
    else:
        for key in params:
            if type(params[key]) == Decimal:
                i.add(key, float(params[key]))
            else:
                i.add(key, params[key])

    if None != extraParams:
        for key in extraParams:
            i.add(key, extraParams[key])

    return i
コード例 #2
0
def sqlInsert(params, extraParams=None, dbType='postgres'):
    '''
	Give the SQL INSERT statement
	@param params: dict keyed by field name of values
	@param extraParams: any extra fields that you have created beyond the normal ais message fields
	@rtype: sqlhelp.insert
	@return: insert class instance
	@todo: allow optional type checking of params?
	@warning: this will take invalid keys happily and do what???
	'''

    i = sqlhelp.insert('binack', dbType=dbType)

    if dbType == 'postgres':
        finished = []
        for key in params:
            if key in finished:
                continue

            if key not in toPgFields and key not in fromPgFields:
                if type(params[key]) == Decimal: i.add(key, float(params[key]))
                else: i.add(key, params[key])
            else:
                if key in fromPgFields:
                    val = params[key]
                    # Had better be a WKT type like POINT(-88.1 30.321)
                    i.addPostGIS(key, val)
                    finished.append(key)
                else:
                    # Need to construct the type.
                    pgName = toPgFields[key]
                    #valStr='GeomFromText(\''+pgTypes[pgName]+'('
                    valStr = pgTypes[pgName] + '('
                    vals = []
                    for nonPgKey in fromPgFields[pgName]:
                        vals.append(str(params[nonPgKey]))
                        finished.append(nonPgKey)
                    valStr += ' '.join(vals) + ')'
                    i.addPostGIS(pgName, valStr)
    else:
        for key in params:
            if type(params[key]) == Decimal: i.add(key, float(params[key]))
            else: i.add(key, params[key])

    if None != extraParams:
        for key in extraParams:
            i.add(key, extraParams[key])

    return i
コード例 #3
0
def sqlInsert(params,extraParams=None,dbType='postgres'):
	'''
	Give the SQL INSERT statement
	@param params: dict keyed by field name of values
	@param extraParams: any extra fields that you have created beyond the normal ais message fields
	@rtype: sqlhelp.insert
	@return: insert class instance
	@todo: allow optional type checking of params?
	@warning: this will take invalid keys happily and do what???
	'''

	i = sqlhelp.insert('b_staticdata',dbType=dbType)

	for key in params:
		if type(params[key])==Decimal: i.add(key,float(params[key]))
		else: i.add(key,params[key])

	if None != extraParams:
		for key in extraParams:
			i.add(key,extraParams[key])

	return i
コード例 #4
0
def sqlInsert(params, extraParams=None, dbType='postgres'):
    '''
	Give the SQL INSERT statement
	@param params: dict keyed by field name of values
	@param extraParams: any extra fields that you have created beyond the normal ais message fields
	@rtype: sqlhelp.insert
	@return: insert class instance
	@todo: allow optional type checking of params?
	@warning: this will take invalid keys happily and do what???
	'''

    i = sqlhelp.insert('b_staticdata', dbType=dbType)

    for key in params:
        if type(params[key]) == Decimal: i.add(key, float(params[key]))
        else: i.add(key, params[key])

    if None != extraParams:
        for key in extraParams:
            i.add(key, extraParams[key])

    return i