Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if None in value: "sqlite3.OperationalError: no such column: None" #4

Closed
void285 opened this issue Jun 12, 2019 · 3 comments
Closed

Comments

@void285
Copy link
Collaborator

void285 commented Jun 12, 2019

Hi, I encountered error in this code:

#coding: utf-8
from medoo import Medoo

db = Medoo(dbtype="sqlite", database="test.db")
db.query('''create table table_1
    (id integer primary key,
    name varchar not null default "",
    cate varchar not null default "",
    ctime int not null default 0
    );''')
data = [
    {'name': None, 'cate': 'Alysia', 'ctime': 1},
    {'name': 'Gwenda', 'cate': 'Chang', 'ctime': 2},
    {'name': 'Fannie', 'cate': 'Jonelle', 'ctime': 3},
    {'name': 'Meggan', 'cate': 'Oliver', 'ctime': 4},
    {'name': 'Rueben', 'cate': 'Estefana', 'ctime': 5},
]
db.insert('table_1', *data)
Traceback (most recent call last):
  File "test2.py", line 18, in <module>
    db.insert('table_1', *data)
  File "C:\Develop\Python27\lib\site-packages\medoo\base.py", line 70, in insert
    return self.query(sql, kwargs.get('commit', True))
  File "C:\Develop\Python27\lib\site-packages\medoo\base.py", line 116, in query
    raise type(ex)(str(ex) + ':\n' + self.sql)
sqlite3.OperationalError: no such column: None:
INSERT INTO "table_1" ("ctime","name","cate") VALUES (1,None,'Alysia'),(2,'Gwenda','Chang'),(3,'Fannie','Jonelle'),(4,'Meggan','Oliver'),(5,'Rueben','Estefana')

And, I once met with this error in a long and complicated insert, the inserted values have None in it, after replacement of None with empty string, the error disappeared. I have no idea about what may have caused it.

  File "C:\Develop\Python27\lib\site-packages\medoo\base.py", line 113, in query
    raise type(ex)(str(ex) + ':\n' + self.sql)
sqlite3.OperationalError: <exception str() failed>
@void285
Copy link
Collaborator Author

void285 commented Jun 12, 2019

Same error if True/False for boolean field in inserted values.

@pwwang
Copy link
Owner

pwwang commented Jun 12, 2019

This is because that there is no boolean values and None for sqlite. I will try to map True to 1, False to 0 and None to NULL.

@pwwang pwwang closed this as completed in 6729187 Jun 12, 2019
@pwwang
Copy link
Owner

pwwang commented Jun 12, 2019

I fixed it at 0.0.4.
However, with your original code, None would be casted into NULL, which will raise an exception since you defined column name as not null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants