Issue
I was trying to connect my .sql database with python version 2.7.9 with this code :
import sqlite3
db = sqlite3.connect("c:\\Users\\afsoon\\Desktop\\ch9learning\\sql\\genres.sql")
cursor = db.cursor()
query = """SELECT * FROM mytable where genre='folk'"""
lines = cursor.execute(query)
data = cursor.fetchall()
db.close()
but I catch this error :
lines = cursor.execute(query)
Traceback (most recent call last):
File "<ipython-input-10-af02982f9f74>", line 1, in <module>
lines = cursor.execute(query)
DatabaseError: file is encrypted or is not a database
I'm on windows and I've got sqlite3!
p.s: these are my database first lines
-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 23, 2015 at 09:29 AM
-- Server version: 10.1.9-MariaDB
-- PHP Version: 5.6.15
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `genres`
--
CREATE DATABASE IF NOT EXISTS `genres` DEFAULT CHARACTER SET utf8 COLLATE utf8_persian_ci;
USE `genres`;
-- --------------------------------------------------------
--
-- Table structure for table `mytable`
--
CREATE TABLE `mytable` (
`genre` varchar(640) COLLATE utf8_persian_ci DEFAULT NULL,
`track_id` varchar(50) COLLATE utf8_persian_ci DEFAULT NULL,
`artist_name` varchar(248) COLLATE utf8_persian_ci DEFAULT NULL,
`title` varchar(248) COLLATE utf8_persian_ci DEFAULT NULL,
`keyy` decimal(13,10) DEFAULT NULL,
`modee` decimal(13,10) DEFAULT NULL,
`duration` decimal(14,10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci;
--
-- Dumping data for table `mytable`
Solution
You have to import your data into SQLite. Since your file is an export of MySQL there might be import problems and you might have to fix some line manually.
But basically you have to create a new SQLite database file and import your SQL. You need the sqlite3 binary for that. Run on the command line:
sqlite3 your_new_db.sqlite
sqlite> .read genres.sql
Answered By - Klaus D.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.