-1

I created this python script using the python-mysqldb package and I am trying to print a requested scripture verse from the Bible.sql file. (Warning: the linked .sql file is large, I have sampled the sql statements below)

I am not entirely familiar with querying SQL databses, all I am able to do thus far is show databases; show tables; and select * from bible;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| openVdev           |
+--------------------+
2 rows in set (0.00 sec)

mysql> show tables;
+--------------------+
| Tables_in_openVdev |
+--------------------+
| bible              |
+--------------------+
1 row in set (0.00 sec)

select * from bible; just dumps everything for me, how can I parse the file for a certain scripture/ bible passage?

Here is a sample of the SQL syntax:

INSERT INTO `bible` VALUES (1,'Genesis',1,1,'IN THE beginning God 
INSERT INTO `bible` VALUES (531,'Genesis',21,17,'And God heard the voice
INSERT INTO `bible` VALUES (1035,'Genesis',35,23,'The sons of Leah: Reuben,
INSERT INTO `bible` VALUES (1531,'Genesis',50,24,'And Joseph said to his brethren,
INSERT INTO `bible` VALUES (1985,'Exodus',17,1,'ALL THE congregation

There are also several versions of the Bible identified by key values:

DROP TABLE IF EXISTS `bible`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `bible` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `book` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
  `chapter` int(11) NOT NULL,
  `verse` int(11) NOT NULL,
  `AMP` text COLLATE utf8_unicode_ci NOT NULL,
  `ASV` text COLLATE utf8_unicode_ci NOT NULL,
  `BENG` text COLLATE utf8_unicode_ci NOT NULL,
  `CEV` text COLLATE utf8_unicode_ci NOT NULL,
  `DARBY` text COLLATE utf8_unicode_ci NOT NULL,
  `ESV` text COLLATE utf8_unicode_ci NOT NULL,
  `KJV` text COLLATE utf8_unicode_ci NOT NULL,
  `MKJV` text COLLATE utf8_unicode_ci NOT NULL,
  `MSG` text COLLATE utf8_unicode_ci NOT NULL,
  `NASB` text COLLATE utf8_unicode_ci NOT NULL,
  `NIV` text COLLATE utf8_unicode_ci NOT NULL,
  `NKJV` text COLLATE utf8_unicode_ci NOT NULL,
  `NLT` text COLLATE utf8_unicode_ci NOT NULL,
  `NRSV` text COLLATE utf8_unicode_ci NOT NULL,
  `WEB` text COLLATE utf8_unicode_ci NOT NULL,
  `YLT` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`book`,`chapter`,`verse`),
  KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=31103 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

I followed this post to create the python-MySQLdb connection

import MySQLdb

db = MySQLdb.connect(host="localhost", # your host, usually localhost
                     user="openVuser", # your username
                      passwd="openVpw", # your password
                      db="openVdev") # name of the data base

# you must create a Cursor object. It will let
#  you execute all the queries you need
cur = db.cursor() 

# Use all the SQL you like
cur.execute("SELECT * FROM bible")

Question_1 = "\n Please enter a scripture?\n"
scripture = raw_input(Question_1)

print scripture


print all the first cell of all the rows
for row in cur.fetchall() :
    print row[0]    

I apologize if it looks like I have not made any effort, but it has been a month of no progress. I have had a hard time figuring out how to query the MySQL db with command lines, although I have been able to make some progress with this tutorial:

mysql> describe bible;
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id      | int(11)     | NO   | MUL | NULL    | auto_increment |
| book    | varchar(25) | NO   | PRI | NULL    |                |
| chapter | int(11)     | NO   | PRI | NULL    |                |
| verse   | int(11)     | NO   | PRI | NULL    |                |
| AMP     | text        | NO   |     | NULL    |                |
| ASV     | text        | NO   |     | NULL    |                |
| BENG    | text        | NO   |     | NULL    |                |
| CEV     | text        | NO   |     | NULL    |                |
| DARBY   | text        | NO   |     | NULL    |                |
| ESV     | text        | NO   |     | NULL    |                |
| KJV     | text        | NO   |     | NULL    |                |
| MKJV    | text        | NO   |     | NULL    |                |
| MSG     | text        | NO   |     | NULL    |                |
| NASB    | text        | NO   |     | NULL    |                |
| NIV     | text        | NO   |     | NULL    |                |
| NKJV    | text        | NO   |     | NULL    |                |
| NLT     | text        | NO   |     | NULL    |                |
| NRSV    | text        | NO   |     | NULL    |                |
| WEB     | text        | NO   |     | NULL    |                |
| YLT     | text        | NO   |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+
20 rows in set (0.00 sec)

I am interested in the KJV key from the Bible table, how could I slect that key and move on to scriptures, and parsing the user received input into an SQL query?

Pseudocode:
Print: What scripture would you like to look up?
User: Romans 12:1
cur.execute("SELECT KJV FROM bible key")
cur.execute("SELECT 'Romans 12:1' FROM table")
print cur.execute
Community
  • 1
  • 1
phillipsK
  • 1,466
  • 5
  • 29
  • 43
  • Your question is not at all about Python or MySQLdb (and definitely not about "parsing"), but is a simple matter of learning enough SQL to request what you want - although you haven't said what that is. You should go and do a basic SQL tutorial. – Daniel Roseman Aug 30 '15 at 13:04
  • @DanielRoseman Thank you do you have a tutorial in mind? – phillipsK Aug 30 '15 at 17:42

1 Answers1

2
/* Generic query */
SELECT `key1`, `key2`, `key3` FROM `table` WHERE `another_key` LIKE 'SOME_STRING';

/* Specific query for your problem */
SELECT `KJV` FROM `bible` WHERE `chapter` LIKE 'Romans' AND `verse` = '12';
Lev
  • 1,698
  • 3
  • 18
  • 26