Skip to content

Commit

Permalink
Sync improves with coding style requirments
Browse files Browse the repository at this point in the history
  • Loading branch information
Enelar committed Apr 17, 2016
1 parent b7aa752 commit 8594546
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
12 changes: 7 additions & 5 deletions mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ public function Query( $q, $p = [] )

$ret = $stmt->fetchAll(\PDO::FETCH_ASSOC);

// If we affect only one row, we could determine affected id
$affected_rows = $stmt->rowCount();
if ($affected_rows == 1)
$this->affected_id = $this->db->lastInsertId();
else
$this->affected_id = false;

$stmt->closeCursor();
unset($stmt);

return $ret;
}

public function lastInsertId()
{
return $this->db->lastInsertId();
}

public function Begin()
{
$this->Query("--BEGIN;");
Expand Down
4 changes: 3 additions & 1 deletion phpsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function Connect( $connection, $params = NULL )
$connector = $this->GetConnector($this->con_params['scheme'], $this->con_params);
return $connector;
}

private function SplitConnectionString( $str )
{
if (!is_string($str))
Expand Down Expand Up @@ -82,4 +82,6 @@ private function GetConnector( $scheme, $a )

return $proxy;
}

public $affected_id = null;
}
14 changes: 11 additions & 3 deletions proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ class proxy extends proxy_storage
{
private $transactions = [];
private $next_transaction_id = 1;
private $last_insert_id = "NOT_AN_ID";

public function OpenConnection( $user, $pass, $ip, $port, $db, $options )
{
return $this->connector->OpenConnection($user, $pass, $ip, $port, $db, $options);
}

public function lastInsertId()
public function AffectedID()
{
$res = $this->connector->lastInsertId();
return $res;
$affected_id = $this->connector->affected_id;

if ($affected_id === null)
throw new \Exception("Unable to determine affected ID. This DB support it?");

if ($affected_id === false)
throw new \Exception("Unable to determine affected ID. Maybe you update multiply rows?");

return $affected_id;
}

public function Query( $query, $params = [], $one_row = false, $reindex_by = null )
Expand Down

0 comments on commit 8594546

Please sign in to comment.