Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
二进制数据未存储在SQLite中,返回null_Sqlite_Blob - Fatal编程技术网

二进制数据未存储在SQLite中,返回null

二进制数据未存储在SQLite中,返回null,sqlite,blob,Sqlite,Blob,打印出数据给了我: \xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00\x84\x00\t\x06\x07\x13\x13\x12\x15\x13\x13\x13\x16\x16\x15\x17\x19\x1a\x1b\x17\x16\x18\x18 因此二进制数据是存在的。但是,当我尝试使用此代码插入值时: for i in check_row:

打印出数据给了我:

\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00\x84\x00\t\x06\x07\x13\x13\x12\x15\x13\x13\x13\x16\x16\x15\x17\x19\x1a\x1b\x17\x16\x18\x18
因此二进制数据是存在的。但是,当我尝试使用此代码插入值时:

        for i in check_row:
            if i[0] == 0:
                db.execute("INSERT INTO profiles (profile_id, city, country, interest, bio, picture) VALUES (:user, :city, :country, :interest, :bio, :picture)",
                [user, city, country, interest, bio, empPicture])
                conn.commit()
                flash("profile completed")
                return redirect("/")
            else:
                db.execute("UPDATE profiles SET city = :city, country = :country, interest = :interest, bio = :bio, picture = :picture WHERE profile_id = :profile_id",
                [city, country, interest, bio, user, empPicture])
                conn.commit()
                flash("profile updated")
                return redirect("/profile")
empPicture
是保存二进制数据的变量。这不会返回任何错误,但是,数据从未被输入到picture BLOB列中,它只是显示NULL,并在运行时打印出None。 这是我的桌子:

CREATE TABLE "profiles" ( "profile_id" INTEGER, "city" TEXT VARCHAR(255), "country" TEXT VARCHAR(255), "interest" TEXT VARCHAR(255), "bio" TEXT VARCHAR(255), "picture" BLOB )

我相信您必须将insert包装到
sqlite3.Binary
中,如下所示:

db.execute("INSERT INTO profiles (profile_id, city, country, interest, bio, picture) VALUES (:user, :city, :country, :interest, :bio, :picture)",
[user, city, country, interest, bio, sqlite3.Binary(empPicture)])
conn.commit()

更多的细节可以找到。

“…请说出ablob的意思”它的意思是(只有5个)
TEXT VARCHAR(255)
也无效。您确定您的问题标记正确吗?例如,CREATETABLE语句类似于[MySQL]。