Well, I just had another issue resolved and have come to another one that baffles me, and as I can find little to no documentation on the pgdb module, I thought I'd sound you guys out again.
I am attempting to insert values into a table in postgresql, and while I have working code that will do this is if specify all the values I am sticking into the database, code that dynaimcally grabs the data from a file and then inserts does not, even though no exceptions are thrown. Im not sure whats up, any ideas?
fa = open(datafilename, 'r')
#THIS BLOCK OF CODE UPDATES MY DB WITH THE LINE SHOWN
db=pgdb.connect(database=databasename, host=hostname,user=username,password=passwd)
cursor = db.cursor()
command = "INSERT INTO buildingarea VALUES (001,'ADAMS COUNTY',99344,46.827354,-119.1742,'COM',1592);"
print(command)
cursor.execute(command)
db.commit()
db.close()
#THIS LINE OF CODE OUTPUTS A COMMAND IN THE PRINT STATEMENT THAT IS IDENTICAL TO THE ONE ABOVE AND RUNS WITH NO ERRORS, BUT NOTHING UPDATES.
for line in fa:
out = line.split(",")
s = ''.join(out)
final = []
for segment in s.split('\x00\x00'):
temp = ''
for char in segment:
if ord(char) > 31:
temp +=char
final.append(temp)
db=pgdb.connect(database=databasename, host=hostname,user=username,password=passwd)
cursor = db.cursor()
command = "INSERT INTO "+tablename+" VALUES ("+final[0]+",'"+final[1]+"',"+final[2]+","+final[3]+","+final[4]+",'"+final[5]+"',"+final[6]+");"
print(command)
cursor.execute(command)
db.commit
cursor.close()
db.close()