/**
  * Return a PDO logger appender that will reference the given bucket id
  *
  * @param ForgeUpgrade_Bucket $bucket The bucket
  *
  * @return LoggerAppenderPDO
  */
 public function getBucketLoggerAppender(ForgeUpgrade_Bucket $bucket)
 {
     $this->initOptions();
     $logger = new LoggerAppenderPDO();
     $logger->setUser($this->user);
     $logger->setPassword($this->password);
     $logger->setDSN($this->dsn);
     $logger->setTable('forge_upgrade_log');
     $logger->setInsertSql('INSERT INTO forge_upgrade_log (id, bucket_id, timestamp, logger, level, message, thread, file, line) VALUES (NULL,' . $bucket->getId() . ',?,?,?,?,?,?,?)');
     $logger->setInsertPattern('%d,%c,%p,%m,%t,%F,%L');
     $logger->activateOptions();
     return $logger;
 }
 /** Tests new style prepared statment logging with customized SQL. */
 public function testCustomizedSql()
 {
     $dateFormat = "Y-m-d H:i:s";
     // Prepare appender
     $appender = new LoggerAppenderPDO("myname");
     $appender->setDSN(self::$dsn);
     $appender->setInsertSql("INSERT INTO log4php_log (file, line, thread, timestamp, logger, level, message) VALUES (?,?,?,?,?,?,?)");
     $appender->setInsertPattern("%F,%L,%t,%d\\{{$dateFormat}\\},%c,%p,%m");
     $appender->activateOptions();
     // Action!
     $event = new LoggerLoggingEvent("LoggerAppenderPDOTest2", new Logger("TEST"), LoggerLevel::getLevelError(), "testmessage");
     $appender->append($event);
     // Check
     $db = new PDO(self::$dsn);
     $result = $db->query("SELECT * FROM log4php_log");
     $row = $result->fetch(PDO::FETCH_OBJ);
     self::assertTrue(is_object($row));
     self::assertEquals("NA", $row->file);
     // "NA" due to phpunit magic
     self::assertEquals("NA", $row->line);
     // "NA" due to phpunit magic
     if (function_exists('posix_getpid')) {
         self::assertEquals(posix_getpid(), $row->thread);
     }
     self::assertEquals(1, preg_match('/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$/', $row->timestamp));
     self::assertEquals('TEST', $row->logger);
     self::assertEquals('ERROR', $row->level);
     self::assertEquals('testmessage', $row->message);
 }
 /** Tests new style prepared statment logging with customized SQL. */
 public function testCustomizedSql()
 {
     if (!extension_loaded('pdo_sqlite')) {
         self::markTestSkipped("Please install 'pdo_sqlite' in order to run this test");
     }
     // Prepare appender
     $appender = new LoggerAppenderPDO("myname");
     $appender->setDSN(self::dsn);
     $appender->setTable('unittest2');
     $appender->setInsertSql("INSERT INTO unittest2 (file, line, thread, timestamp, logger, level, message) VALUES (?,?,?,?,?,?,?)");
     $appender->setInsertPattern("%F,%L,%t,%d,%c,%p,%m");
     $appender->activateOptions();
     // Action!
     $event = new LoggerLoggingEvent("LoggerAppenderPDOTest2", new Logger("TEST"), LoggerLevel::getLevelError(), "testmessage");
     $appender->append($event);
     // Check
     $db = new PDO(self::dsn);
     $result = $db->query("SELECT * FROM unittest2");
     $row = $result->fetch(PDO::FETCH_OBJ);
     self::assertTrue(is_object($row));
     self::assertEquals("NA", $row->file);
     // "NA" due to phpunit magic
     self::assertEquals("NA", $row->line);
     // "NA" due to phpunit magic
     self::assertEquals(posix_getpid(), $row->thread);
     self::assertEquals(1, preg_match('/^\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d.\\d\\d\\d$/', $row->timestamp));
     self::assertEquals('TEST', $row->logger);
     self::assertEquals('ERROR', $row->level);
     self::assertEquals('testmessage', $row->message);
 }