How to cat strings together that may be NULL?
I am trying to cat several fields together into one string from a mysql table. I keep getting an error about "Cannot add type "None" to string". I am guessing that some of my feilds are NULL. My goal is to copy the columns from one table and dump them into one column of another. I have this: <dtml-in sqlGetTableColumns> <dtml-call "REQEST.set('tbldata', Field1, Field2, Field3, Field4)"> <dtml-call "sqlInsertDump(DumpCol=tbldata,User=AUTHENTICATED_USER)"> </dtml-in> Field3 and Field4 are usually NULL, but not always, so I want to capture them as well. Any suggestions? Thanks! Greg
From: "Greg" <sysman@techgroupinc.com>
Field3 and Field4 are usually NULL, but not always, so I want to capture them as well.
Any suggestions?
Depends on what you want a "None" should be converted to. using str(Field3) will make it return 'None', which may be wrong. Then you can use (Field3 or ''), which will return '' when Field3 is none.
Thanks for the pointer! This is what I did with your help: <dtml-in sqlGetTableColumns> <dtml-call "REQEST.set('tbldata', _.str(Field1)+':'+_.str(Field2))"> <dtml-call "sqlInsertDump(DumpCol=tbldata,User=AUTHENTICATED_USER)"> </dtml-in> That worked perfectly! All the fields were inserted into another table, delimited by ':' for later retrieval. If the fields were null, they showed as None. Greg Lennart Regebro wrote:
From: "Greg" <sysman@techgroupinc.com>
Field3 and Field4 are usually NULL, but not always, so I want to capture them as well.
Any suggestions?
Depends on what you want a "None" should be converted to. using str(Field3) will make it return 'None', which may be wrong. Then you can use (Field3 or ''), which will return '' when Field3 is none.
participants (2)
-
Greg -
Lennart Regebro