Permalink
Browse files

Started SQL class. Started SQLi class for table installs. Added place…

…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...
1 parent c80c8ba commit 3c51de206fce02555f5e62f8a4dc811696afe572 @b-turchyn committed Apr 25, 2011
View
@@ -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 "
}
-?>
+?>
@@ -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());
+ }
+ }
+}
+?>
@@ -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;
+
@@ -0,0 +1 @@
+75b37d9a300ffdb392dd4701a4b92cff7e7169cd
@@ -0,0 +1 @@
+da39a3ee5e6b4b0d3255bfef95601890afd80709
@@ -0,0 +1 @@
+da39a3ee5e6b4b0d3255bfef95601890afd80709
@@ -0,0 +1 @@
+da39a3ee5e6b4b0d3255bfef95601890afd80709
@@ -0,0 +1 @@
+da39a3ee5e6b4b0d3255bfef95601890afd80709
@@ -0,0 +1 @@
+da39a3ee5e6b4b0d3255bfef95601890afd80709
@@ -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.