1

I am using python 2.7.6 and sqlite3. Here the part of code which must create the table named goods:

c.execute("""create table goods(
                            Art varchar(12) primary key,
                            Name_G varchar(30),
                            Meas varchar(3),
                            Price_G double unsigned,

                            check (Meas in ('кг.','л.','шт.')))""")

Don't blame me for such method, it's the exercise requirement. THe field Meas can contain only one of three strings. They are listed in constraint and they are in Russian. This query executes succesfully but if I check the data in database I see it stores the following SQL:

CREATE TABLE goods(
                            Art varchar(12) primary key,
                            Name_G varchar(30),
                            Meas varchar(3),
                            Price_G double unsigned,

                            check (Meas in ('кг.','л.','шт.')))

As you can see, it's not Russian. Is there any method to store correct data in the database? encode() method, u'' didn't work for me.

3
  • It's UTF-8 representation of Cyrillic (Russian) letters. Commented Apr 10, 2014 at 9:53
  • Did you, at any time, use the Windows Command Prompt? Commented Apr 10, 2014 at 16:47
  • Well. The problem was related to my Sqlite viewer. It shown the incorrect data when it was correct. Paradox. Commented Apr 11, 2014 at 20:01

1 Answer 1

2

The following instructions work correctly for me:

alex@rhyme ~/tmp $ echo $LANG
ru_RU.UTF-8
alex@rhyme ~/tmp $ python    
Python 2.7.6 (default, Feb  5 2014, 11:50:47) 
[GCC 4.7.2 20121109 (ALT Linux 4.7.2-alt8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> db = sqlite3.connect('sample1.db')
>>> c = db.cursor()
>>> c1 = c.execute('PRAGMA encoding="UTF-8";')
>>> c1 = c.execute('CREATE TABLE sample (id INTEGER PRIMARY KEY AUTOINCREMENT, t VARCHAR(3) NOT NULL DEFAULT  "руб");')
>>> c1 = c.execute('INSERT INTO sample DEFAULT VALUES;')
>>> db.commit()
Sign up to request clarification or add additional context in comments.

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.