I’ve written a python script that adds student data (name and classes) to a table one at a time. The table is structured so that there is a primary key column, a student name column, and then a column for each class. The script checks to see if the class it’s adding already exists as a column, and if not it creates it. Then it writes ‘true’ under that column for the current student.
Here’s my problem: from the log file I can see that every single query is sent to the database correctly, but some don’t show up in the table. When I run these queries:
CREATE TABLE Students (idStudents INT NOT NULL, Name VARCHAR(255) NOT NULL, PRIMARY KEY (idStudents)) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8
SET NAMES 'utf8'
INSERT INTO Students (idStudents, Name) VALUES ('1', 'Bror Tao Sjørslev Bojlen')
SELECT column_name FROM information_schema.columns WHERE table_name='Students'
ALTER TABLE Students ADD 3ubmSL5 VARCHAR(20)
UPDATE Students SET 3ubmSL5='true' WHERE idStudents='1'
ALTER TABLE Students ADD 3uchSL3 VARCHAR(20)
UPDATE Students SET 3uchSL3='true' WHERE idStudents='1'
ALTER TABLE Students ADD 3udaBH3 VARCHAR(20)
UPDATE Students SET 3udaBH3='true' WHERE idStudents='1'
ALTER TABLE Students ADD 3uenA1H1 VARCHAR(20)
UPDATE Students SET 3uenA1H1='true' WHERE idStudents='1'
ALTER TABLE Students ADD 3umaHL4 VARCHAR(20)
UPDATE Students SET 3umaHL4='true' WHERE idStudents='1'
ALTER TABLE Students ADD 3uphH2 VARCHAR(20)
UPDATE Students SET 3uphH2='true' WHERE idStudents='1'
ALTER TABLE Students ADD 3uth1 VARCHAR(20)
UPDATE Students SET 3uth1='true' WHERE idStudents='1'
the table looks like this.
That is, the final query
UPDATE Students SET 3uth1='true' WHERE idStudents='1'
doesn’t go through.
I hope this makes sense, and someone can shed some light on this issue – it’s driving me crazy.
I suspect the final statement is being rolled back. I’m guessing that your client is wrapping the statements implicitly in a transaction. I have seen specifically Navicat roll back transactions containing inserts or updates that aren’t explicitly committed unless they are accompanied by another statement. It’s odd behavior, but I’ve watched it through a trace.
As an aside, your table design is rather unconventional. Students and classes are distinct entities and should not be stored in the same table. You are combining at least three different tables here; this will not scale well.
EDIT:
In fact, the first question I posted here involved this issue:
Unable to insert record from stored procedure called from web service
I just remembered that. 🙂