* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontendInterface {
+ // Constants for MySQL backward-compatiblity (PLEASE FIX THEM!)
+ const DB_CODE_TABLE_MISSING = 0x000;
+
/**
* Save path for "file database"
*/
*/
private $alreadyConnected = false;
+ /**
+ * Last error message
+ */
+ private $lastError = "";
+
+ /**
+ * Last exception
+ */
+ private $lastException = null;
+
/**
* The private constructor. Do never instance from outside!
* You need to set a local file path. The class will then validate it.
return $this->savePath;
}
+ /**
+ * Getter for last error message
+ *
+ * @return $lastError Last error message
+ */
+ public final function getLastError () {
+ return $this->lastError;
+ }
+
+ /**
+ * Getter for last exception
+ *
+ * @return $lastException Last thrown exception
+ */
+ public final function getLastException () {
+ return $this->lastException;
+ }
+
/**
* Saves a given object to the local file system by serializing and
* transparently compressing it
$this->lastFile = $fqfn;
}
+ /**
+ * Reset the last error and exception instance. This should be done after
+ * a successfull "query"
+ *
+ * @return void
+ */
+ private final function resetLastError () {
+ $this->lastError = "";
+ $this->lastException = null;
+ }
+
/**
* Getter for last read file
*
* @param $criteria Local search criteria class
* @return $resultData Result data of the query
* @throws UnsupportedCriteriaException If the criteria is unsupported
+ * @throws SqlException If an "SQL error" occurs
*/
public function querySelect ($resultType, $tableName, Criteria $criteriaInstance) {
+ // The result is null by any errors
+ $resultData = null;
+
// Is this criteria supported?
if (!$criteriaInstance instanceof LocalCriteria) {
// Not supported by this database layer
throw new UnsupportedCriteriaException(array($this, $criteriaInstance), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
}
- // A "select" query on local files is not that easy, so begin slowly with it...
- $this->partialStub(sprintf("type=%s,table=%s,criteria=%s", $resultType, $tableName, $criteriaInstance));
+ // Create full path name
+ $pathName = $this->getSavePath() . $tableName . '/';
+
+ // A "select" query is not that easy on local files, so first try to
+ // find the "table" which is in fact a directory on the server
+ try {
+ // Get a directory pointer instance
+ $directoryPointer = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($pathName);
+ $this->partialStub("Finish handling found "tables"");
+
+ // Reset last error message and exception
+ $this->resetLastError();
+ } catch (PathIsNoDirectoryException $e) {
+ // Path not found means "table not found" for real databases...
+ $this->lastException = $e;
+ $this->lastError = $e->getMessage();
+
+ // So throw an SqlException here with faked error message
+ throw new SqlException (array($this, sprintf("Table '%s' not found", $tableName), self::DB_CODE_TABLE_MISSING), self::EXCEPTION_SQL_QUERY);
+ } catch (FrameworkException $e) {
+ // Catch all exceptions and store them in last error
+ $this->lastException = $e;
+ $this->lastError = $e->getMessage();
+ }
+
+ // Return the gathered result
+ return $resultData;
}
}