I've run into a problem with my ruby ORM using sqlite3
my orm has a save function that saves a record in the database and sets the objects instance id to the id of the new record:
def save
sql = "INSERT INTO #{table_name_for_insert} (#{col_names_for_insert}) VALUES (#{values_for_insert})"
DB[:conn].execute(sql)
@id = DB[:conn].execute("SELECT last_insert_rowid() FROM #{table_name_for_insert}")[0][0]
end
table_name_for_insert
returns "students"col_names_for_insert
returns "name, grade"values_for_insert
returns "'Sam', '11'"
This all "works" per se, however, when SELECT * FROM students
is run after the save method the record returned is:
[{"id" => 1,
'name" => "Sam",
"grade => 11,
0 => 1,
1 => "Sam",
2 => 11 }]
I expect the first 3 columns but I have no idea why the last three exist.
If anyone knows whats going on i appreciate it, I'm sure this is a stupid mistake on my part.
students
table schema, and show the code that ran theSELECT * FROM students
and how the result was observed?