Skip to content

Commit

Permalink
Started SQL class. Started SQLi class for table installs. Added place…
Browse files Browse the repository at this point in the history
…holders for some of the table generation. Wrote bash script to generate SHA1 checksums for SQL queries to reduce risk of inserting bad data into table.
  • Loading branch information
b-turchyn committed Apr 25, 2011
1 parent c80c8ba commit 3c51de2
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/classes/sql.php
@@ -1,6 +1,29 @@
<?php

class MySQLQueries {

// List of all eras
private const $getEras =
"SELECT * FROM ?eras ORDER BY name ASC";

// Count number of first names
private const $getFirstNameCount =
"SELECT COUNT(*) FROM ?names " +
"WHERE isfirstname_sw = true " +
"AND deleted_dt IS NOT NULL";

// Count number of last names
private const $getLastNameCount =
"SELECT COUNT(*) FROM ?names " +
"WHERE isfirstname_sw = false " +
"AND deleted_dt IS NOT NULL";

// Retrieve first and last name from a random index
private const $getFullName =
"SELECT name FROM ?names " +
"WHERE isfirstname_sw = true " +
"LIMIT ?, 1 " +
"UNION SELECT name FROM ?names " +
"WHERE isfirstname_sw = false " +
"LIMIT ?, 1 "
}
?>
?>
21 changes: 21 additions & 0 deletions src/install/classes/sqli.php
@@ -0,0 +1,21 @@
<?php
/**
* SQLi Class
* Handles all database interactions for installation
*
* @package src/install
* @author Brian Turchyn
*/

class SQLiInstall extends mysqli {
private $handle;

public function __construct($host, $user, $pass, $database) {
parent::__construct($host, $user, $pass, $database);
// Check for errors
if($this->connect_error()) {
die("Connection error (" . $this->connect_errno() . ") " . $this->connect_error());
}
}
}
?>
7 changes: 7 additions & 0 deletions src/install/tabledata/001-create-table-eras.sql
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS ?eras
( era_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
era_name VARCHAR(128) NOT NULL,
deleted_dt TIMESTAMP NULL DEFAULT NULL )
ENGINE=MyISAM
DEFAULT CHARACTER SET = utf8;

1 change: 1 addition & 0 deletions src/install/tabledata/001-create-table-eras.sql.sha1
@@ -0,0 +1 @@
75b37d9a300ffdb392dd4701a4b92cff7e7169cd
Empty file.
1 change: 1 addition & 0 deletions src/install/tabledata/002-create-table-names.sql.sha1
@@ -0,0 +1 @@
da39a3ee5e6b4b0d3255bfef95601890afd80709
Empty file.
1 change: 1 addition & 0 deletions src/install/tabledata/003-create-table-countries.sql.sha1
@@ -0,0 +1 @@
da39a3ee5e6b4b0d3255bfef95601890afd80709
Empty file.
1 change: 1 addition & 0 deletions src/install/tabledata/004-create-table-cities.sql.sha1
@@ -0,0 +1 @@
da39a3ee5e6b4b0d3255bfef95601890afd80709
Empty file.
1 change: 1 addition & 0 deletions src/install/tabledata/005-create-table-colleges.sql.sha1
@@ -0,0 +1 @@
da39a3ee5e6b4b0d3255bfef95601890afd80709
Empty file.
@@ -0,0 +1 @@
da39a3ee5e6b4b0d3255bfef95601890afd80709
42 changes: 42 additions & 0 deletions src/install/tabledata/genSHA1.sh
@@ -0,0 +1,42 @@
#!/bin/bash

######################################################################
# SHA1 Checksum Generator
# Using this will re-generate all checksums for all SQL queries.
#
# @package src/install
# @author Brian Turchyn
######################################################################

shopt -s nullglob

clear

echo '===================================================================='
echo '= ='
echo '= !!! WARNING !!! ='
echo '= ='
echo '= This will re-generate all SHA1 checksums for your SQL install ='
echo '= queries. Doing this will defeat the purpose of the checksums ='
echo '= being in place. ='
echo '= ='
echo '= Only use this if you know what you are doing! ='
echo '= ='
echo '===================================================================='
echo
echo
echo "Press Ctrl+C NOW if you want to back out of this."

read -n 1 -s

echo
echo

for f in *.sql
do
echo "Generating SHA1 checksum for $f..."
sha1 -q $f > $f.sha1
done

echo
echo 'Done!'

0 comments on commit 3c51de2

Please sign in to comment.