```
StreamData = {
"D1_RSET":{
'sqltype':'int',
'data':'61207'
},
"D2_DCK_time":{
'sqltype': 'DATETIME',
'data': '2018-9-9'
},
"D3_DCK_des":{
'sqltype': 'varchar(10)',
'data': 'TestABC'
},
"D4_Exp":{
'sqltype': 'varchar(80)',
'data': ''
},
"D5_stream_seq":{
'sqltype': 'int',
'data': '123'
},
}
insertoTableSqlStr_Prefix = 'INSERT INTO {tableName} ({colNames}) value ({colValues})'
colNames = []
colValues = []
def f(sqltype="int", data=None, **kwargs):
if not data:
return None
if sqltype == "int":
return str(data) if data else 'null'
return "\"{}\"".format(data)
for col_name, col_value in StreamData.items():
data = f(**col_value)
if data is None:
continue
colValues.append(data)
colNames.append(col_name)
print colValues, colNames
print insertoTableSqlStr_Prefix.format(tableName='test', colNames=",".join(colNames), colValues=",".join(colValues))
```
insertoTableSqlStr_Prefix = 'INSERT INTO {tableName} ({colNames}) value ({colValues})'
colNames = []
colValues = []
def f(sqltype="int", data=None, **kwargs):
if not data:
return None
if sqltype == "int":
return str(data) if data else 'null'
return "\"{}\"".format(data)
for col_name, col_value in StreamData.items():
data = f(**col_value)
if data is None:
continue
colValues.append(data)
colNames.append(col_name)
print colValues, colNames
print insertoTableSqlStr_Prefix.format(tableName='test', colNames=",".join(colNames), colValues=",".join(colValues))
这样写符合需要吗?
D4_Exp 是不用操作,因为它是空的. 空字符串和 null 还是不一样。 不一定它是个空字符串,就不需要处理。