Skip to content

Instantly share code, notes, and snippets.

@nickvergessen
Created October 19, 2012 08:57
Show Gist options
  • Save nickvergessen/3917045 to your computer and use it in GitHub Desktop.
Save nickvergessen/3917045 to your computer and use it in GitHub Desktop.
Update with math using new values?
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_dbal_update_math_test extends phpbb_database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/update_math_test.xml');
}
public function test_update_math()
{
$db = $this->new_dbal();
$sql = 'UPDATE phpbb_users
SET user_lastvisit = 8,
user_lastmark = 16,
user_lastpost_time = user_lastvisit + user_lastmark';
$db->sql_query($sql);
$sql = 'SELECT user_lastpost_time
FROM phpbb_users';
$result = $db->sql_query($sql);
$this->assertEquals(24, $db->sql_fetchfield('user_lastpost_time'));
$db->sql_freeresult($result);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_users">
<column>user_id</column>
<column>user_lastvisit</column>
<column>user_lastmark</column>
<column>user_lastpost_time</column>
<column>user_permissions</column>
<column>user_sig</column>
<column>user_occ</column>
<column>user_interests</column>
<row>
<value>1</value>
<value>1</value>
<value>2</value>
<value>4</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
</table>
</dataset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment