[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[165] trunk/0.3/cs_phpDB.class.php
Status: Beta
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2010-06-15 02:11:01
|
Revision: 165
http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=165&view=rev
Author: crazedsanity
Date: 2010-06-15 02:10:54 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
Minor logic changes & ability to execute an entire SQL file.
/cs_phpDB.class.php:
* run_query():
-- shorten minimum SQL length to 15 (technically, valid SQL could be
shorter if it were calling a stored proc or "NOW()")
* run_sql_file() [NEW]:
-- execute the contents of an SQL file (for schema & such).
Modified Paths:
--------------
trunk/0.3/cs_phpDB.class.php
Modified: trunk/0.3/cs_phpDB.class.php
===================================================================
--- trunk/0.3/cs_phpDB.class.php 2010-06-15 02:07:39 UTC (rev 164)
+++ trunk/0.3/cs_phpDB.class.php 2010-06-15 02:10:54 UTC (rev 165)
@@ -93,8 +93,8 @@
$retval = array();
- //length must be 19 as that's about the shortest valid SQL: "select * from table"
- if(strlen($sql) >= 19) {
+ //length must be 15 as that's about the shortest valid SQL: "select * from x"
+ if(strlen($sql) >= 15) {
$this->exec($sql);
$numRows = $this->numRows();
@@ -187,6 +187,36 @@
}//end reconnect()
//=========================================================================
+
+ //=========================================================================
+ /**
+ * Execute the entire contents of the given file (with absolute path) as SQL.
+ */
+ public function run_sql_file($filename) {
+ if(!is_object($this->fsObj)) {
+ if(class_exists('cs_fileSystem')) {
+ $fsObj = new cs_fileSystem(dirname($filename));
+ }
+ else {
+ throw new exception(__METHOD__ .": required library (cs_fileSystem) not found");
+ }
+ }
+
+ $this->lastSQLFile = $filename;
+
+ $fileContents = $fsObj->read($filename);
+ try {
+ $this->db->run_update($fileContents, true);
+ $this->build_cache();
+ $retval = TRUE;
+ }
+ catch(exception $e) {
+ $retval = FALSE;
+ }
+
+ return($retval);
+ }//end run_sql_file()
+ //=========================================================================
} // end class phpDB
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|