Programs: SQLite database 3.14.1 & Python 2.7
I have a table called transactions. The field "name" has names in it. I can use Python to return the rows from selected fields to a text file based on criteria specified from tranType while adding some strings to it on the fly:
e = open("export.txt", "w+")
sqlF1 = """SELECT name, quantity, item, tDate, tranType FROM transactions WHERE tranType LIKE "%sell%"
"""
c.execute(sqlF1)
for row in c.execute(sqlF1):
e.write('%s bought QTY %s of %s from %s on date %s\n' % row)
e.close()
This is fine and good. In the name field, sometimes there are first and last names and sometimes it's just the first name.
What I want to do is, while getting each row, check the name - if there is a space in the field (like a first last entry), change the space to a "+" symbol on the fly. I don't want to change the field beforehand and replace all the spaces with pluses.
Can this be done?
What I know/don't know:
Based on my limited knowledge and experience, I can't figure out how to do it. I was thinking the only way I can make this happen is to dump the names into another field and change all the spaces to pluses and then redo the SQL part to grab the different field.
Any advice is greatly appreciated. I'm taking some Python courses soon (and doing some studying on SQLite too, so hopefully I won't be continuously inundating StackOverflow with too many dumb questions.
Thanks!
With the replace() function, this can be done on the fly:
SELECT replace(name, ' ', '+'), quantity, item, tDate FROM ...