コード例 #1
0
 /**
  * Tests that the MDB2::loadClass() method correctly loads classes.
  */
 function test_loadClass()
 {
     $this->assertTrue(MDB2::loadClass('MDB2', false), 'loadClass');
     // Suppress handling of PEAR errors while testing next case
     PEAR::pushErrorHandling(null);
     $result = MDB2::loadClass('null', false);
     $this->assertTrue(is_a($result, 'pear_error'), 'loadClass');
     PEAR::popErrorHandling();
 }
コード例 #2
0
ファイル: Schema.php プロジェクト: CDN-Sparks/owncloud
 /**
  * Dump a previously parsed database structure in the Metabase schema
  * XML based format suitable for the Metabase parser. This function
  * may optionally dump the database definition with initialization
  * commands that specify the data that is currently present in the tables.
  *
  * @param array $database_definition multi dimensional array that contains the current definition
  * @param array $arguments           associative array that takes pairs of tag
  * names and values that define dump options.
  *                 <pre>array (
  *                     'output_mode'    =>    String
  *                         'file' :   dump into a file
  *                         default:   dump using a function
  *                     'output'        =>    String
  *                         depending on the 'Output_Mode'
  *                                  name of the file
  *                                  name of the function
  *                     'end_of_line'        =>    String
  *                         end of line delimiter that should be used
  *                         default: "\n"
  *                 );</pre>
  * @param int   $dump                Int that determines what data to dump
  *              + MDB2_SCHEMA_DUMP_ALL       : the entire db
  *              + MDB2_SCHEMA_DUMP_STRUCTURE : only the structure of the db
  *              + MDB2_SCHEMA_DUMP_CONTENT   : only the content of the db
  *
  * @return bool|MDB2_Error MDB2_OK or error object
  * @access public
  */
 function dumpDatabase($database_definition, $arguments, $dump = MDB2_SCHEMA_DUMP_ALL)
 {
     $class_name = $this->options['writer'];
     $result = MDB2::loadClass($class_name, $this->db->getOption('debug'));
     if (PEAR::isError($result)) {
         return $result;
     }
     // get initialization data
     if (isset($database_definition['tables']) && is_array($database_definition['tables']) && $dump == MDB2_SCHEMA_DUMP_ALL || $dump == MDB2_SCHEMA_DUMP_CONTENT) {
         foreach ($database_definition['tables'] as $table_name => $table) {
             $fields = array();
             $fieldsq = array();
             foreach ($table['fields'] as $field_name => $field) {
                 $fields[$field_name] = $field['type'];
                 $fieldsq[] = $this->db->quoteIdentifier($field_name, true);
             }
             $query = 'SELECT ' . implode(', ', $fieldsq) . ' FROM ';
             $query .= $this->db->quoteIdentifier($table_name, true);
             $data = $this->db->queryAll($query, $fields, MDB2_FETCHMODE_ASSOC);
             if (PEAR::isError($data)) {
                 return $data;
             }
             if (!empty($data)) {
                 $initialization = array();
                 $lob_buffer_length = $this->db->getOption('lob_buffer_length');
                 foreach ($data as $row) {
                     $rows = array();
                     foreach ($row as $key => $lob) {
                         if (is_resource($lob)) {
                             $value = '';
                             while (!feof($lob)) {
                                 $value .= fread($lob, $lob_buffer_length);
                             }
                             $row[$key] = $value;
                         }
                         $rows[] = array('name' => $key, 'group' => array('type' => 'value', 'data' => $row[$key]));
                     }
                     $initialization[] = array('type' => 'insert', 'data' => array('field' => $rows));
                 }
                 $database_definition['tables'][$table_name]['initialization'] = $initialization;
             }
         }
     }
     $writer = new $class_name($this->options['valid_types']);
     return $writer->dumpDatabase($database_definition, $arguments, $dump);
 }
コード例 #3
0
ファイル: Database.php プロジェクト: Alphenus/ilmomasiina-php
<?php

require_once "CommonTools.php";
// Let's do a little hack. We need the configuration information now, because
// we must get the DBinterface with the help of rootDir. So, we must
// create configuration method in this point
$configurations = new Configurations();
// Connection $conn is made in DBInterface.php
require_once dirname(__FILE__) . "/../DBInterface.php";
// To the ageLessThan function
define("TIMEUNIT_DAYS", "days");
define("TIMEUNIT_MINUTES", "minutes");
// Warnings disabled
@MDB2::loadClass("MDB2_Driver_Datatype_Common", false);
@MDB2::loadClass("MDB2_Date", false);
@($MDB2Datatype = new MDB2_Driver_Datatype_Common());
$conn->loadModule('Datatype');
class Database
{
    var $configurations;
    var $page;
    var $debugger;
    var $connection;
    function Database()
    {
        global $configurations, $page, $debugger;
        $this->configurations =& $configurations;
        $this->page =& $page;
        $this->debugger =& $debugger;
        /*
        Tämä kaikki on aika turhaa, kun otaxille siirryttäessä tein 
コード例 #4
0
ファイル: MDB2.php プロジェクト: Alphenus/ilmomasiina-php
 /**
  * loads a module
  *
  * @param   string  name of the module that should be loaded
  *                  (only used for error messages)
  * @param   string  name of the property into which the class will be loaded
  * @param   bool    if the class to load for the module is specific to the
  *                  phptype
  *
  * @return  object  on success a reference to the given module is returned
  *                  and on failure a PEAR error
  *
  * @access  public
  */
 function loadModule($module, $property = null, $phptype_specific = null)
 {
     if (!$property) {
         $property = strtolower($module);
     }
     if (!isset($this->{$property})) {
         $version = $phptype_specific;
         if ($phptype_specific !== false) {
             $version = true;
             $class_name = 'MDB2_Driver_' . $module . '_' . $this->phptype;
             $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
         }
         if ($phptype_specific === false || !MDB2::classExists($class_name) && !MDB2::fileExists($file_name)) {
             $version = false;
             $class_name = 'MDB2_' . $module;
             $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
         }
         $err = MDB2::loadClass($class_name, $this->getOption('debug'));
         if ((new PEAR())->isError($err)) {
             return $err;
         }
         // load module in a specific version
         if ($version) {
             if (method_exists($class_name, 'getClassName')) {
                 $class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
                 if ($class_name != $class_name_new) {
                     $class_name = $class_name_new;
                     $err = MDB2::loadClass($class_name, $this->getOption('debug'));
                     if ((new PEAR())->isError($err)) {
                         return $err;
                     }
                 }
             }
         }
         if (!MDB2::classExists($class_name)) {
             $err = $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, "unable to load module '{$module}' into property '{$property}'", __FUNCTION__);
             return $err;
         }
         $this->{$property} = new $class_name($this->db_index);
         $this->modules[$module] = $this->{$property};
         if ($version) {
             // this will be used in the connect method to determine if the module
             // needs to be loaded with a different version if the server
             // version changed in between connects
             $this->loaded_version_modules[] = $property;
         }
     }
     return $this->{$property};
 }
コード例 #5
0
ファイル: Schema.php プロジェクト: hostinger/revive-adserver
 /**
  * Parse a changeset definition file by creating a schema
  * parser object and passing the file contents as parser input data stream.
  *
  * @param string the changeset schema file.
  * @param array associative array that the defines the text string values
  *              that are meant to be used to replace the variables that are
  *              used in the schema description.
  * @param bool make function fail on invalid names
  * @param array database structure definition
  * @access public
  */
 function parseDictionaryDefinitionFile($input_file, $variables = array(), $fail_on_invalid_names = true, $structure = false)
 {
     $dtd_file = $this->options['dtd_file'];
     if ($dtd_file) {
         require_once 'XML/DTD/XmlValidator.php';
         $dtd = new XML_DTD_XmlValidator();
         if (!$dtd->isValid($dtd_file, $input_file)) {
             return $this->customRaiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage());
         }
     }
     require_once "MDB2/Schema/ParserDictionary.php";
     $class_name = 'MDB2_Dictionary_Parser';
     $result = MDB2::loadClass($class_name, $this->db->getOption('debug'));
     if (PEAR::isError($result)) {
         return $result;
     }
     $parser = new $class_name($variables, $fail_on_invalid_names, $structure, $this->options['valid_types'], $this->options['force_defaults']);
     $class_name = 'MDB2_Schema_Validate';
     $parser->val = new $class_name($fail_on_invalid_names, $this->options['valid_types'], $this->options['force_defaults']);
     $result = $parser->setInputFile($input_file);
     if (PEAR::isError($result)) {
         return $result;
     }
     $result = $parser->parse();
     if (PEAR::isError($result)) {
         return $result;
     }
     if (PEAR::isError($parser->error)) {
         return $parser->error;
     }
     $dictionary = $parser->dictionary_definition;
     return $dictionary;
 }
コード例 #6
0
ファイル: InternalsTest.php プロジェクト: gauthierm/MDB2
 /**
  * Tests that the MDB2::loadClass() method correctly loads classes.
  * @dataProvider provider
  */
 public function test_loadClass($ci)
 {
     $this->manualSetUp($ci);
     $this->assertTrue(MDB2::loadClass('MDB2', false), 'loadClass');
     // Suppress handling of PEAR errors while testing next case
     $this->db->pushErrorHandling(null);
     $result = MDB2::loadClass('null', false);
     $this->assertTrue(is_object($result) && is_a($result, 'pear_error'), 'loadClass');
     $this->db->popErrorHandling();
 }