0

i run following codes in python3:

import sqlite3
conn = sqlite3.connect("data.db")
conn.execute("create table if not exists data(\
              id int prinmary key,view int)")
conn.execute("insert into data (id,view) values (0,0)")
conn.execute("insert into data (id,view) values (1,'--')")
print(conn.execute("select * from data order by id").fetchall())
conn.commit()
conn.close()

and no error occured, "[(0, 0), (1, '--')]" was printed, why?

1
  • SQLite has dynamic typing. Commented Mar 4, 2018 at 9:54

2 Answers 2

2

It is documented as a feature in SQLite documentation, is is even documented is its FAQ:

(3) SQLite lets me insert a string into a database column of type integer!

This is a feature, not a bug. SQLite uses dynamic typing. It does not enforce data type constraints. Data of any type can (usually) be inserted into any column...

Sign up to request clarification or add additional context in comments.

Comments

-1

From the sqlite page: INSERT INTO table1 ( column1, column2 ,..) VALUES ( value1, value2 ,...);

After insert into data, you would need to tell it into which fields.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.