ProgrammingError: (1064

Help
2004-09-20
2012-09-19
  • Juris Program
    Juris Program
    2004-09-20

    Thanks for the help. I used the %s thing and everything works great now.

    You mentioned not using semi-colons on the SQL statements and I tried removing them. However I noticed that my function below doesn't work when it does not end with a semi-colon. Any ideas why that would be? Is the \n a problem? Thanks, Greg

    def CreateSQL(self):
        TableName=self.components['txtTableName'].text
        TempValues=[]
        for RowName in self._widgets:
            TempValues.append([])
            TempValues[-1].append(self.components[RowName[1]].text)
            TempValues[-1].append(self.components[RowName[2]].checked)
            TempValues[-1].append(self.components[RowName[3]].text)
            TempValues[-1].append(self.components[RowName[4]].checked)
            TempValues[-1].append(self.components[RowName[5]].checked)
            TempValues[-1].append(self.components[RowName[6]].checked)
            TempValues[-1].append(self.components[RowName[7]].text)
            TempValues[-1].append(self.components[RowName[8]].stringSelection)
            TempValues[-1].append(self.components[RowName[9]].text)
        #create_definition:
        #col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
        #   [PRIMARY KEY]  [COMMENT 'string'] [reference_definition]
        #
        create_definitions=''
        for row in TempValues:
            create_definitions+=',' + row[8]+self.FormType(row[7],row[6])+self.FormNull(row[5])+self.FormDefault(row[2])+self.FormAutoIncrement(row[3])+self.FormPrimaryKey(row[4])+self.FormComment(row[0])+'\n'
        create_definitions=create_definitions[1:] #remove comma
        stmt="CREATE TABLE IF NOT EXISTS " + TableName + " (" + "\n" + create_definitions + ");"
        print stmt
        try:
            self.parent._database._cursor.execute(stmt)
        except:
            result=self.parent._database._cursor.fetchall()
            print result
            #raise
            return False
        else:
            result=self.parent._database._cursor.fetchall()
            print result
            return True
    
     
  • Juris Program
    Juris Program
    2004-09-20

    whoah, the tabs didn't hold! sorry.

    If you can't read my function, this is the value in variable stmt right before self.parent._database._cursor.execute(stmt)
    So basically it only works with the semicolon at the end.

    CREATE TABLE IF NOT EXISTS testtable1 (
    var1 TINYINT(2) NOT NULL AUTO_INCREMENT PRIMARY KEY
    ,var2 TINYINT(2) NULL
    ,var3 TINYINT(2) NULL
    );

     
  • Juris Program
    Juris Program
    2004-09-21

    Ok, I answered my own question. It seems to be caused by the newline character. Guess you can't do that.

    (Should have tried that before asking.... sorry)

    Greg