Merge branch 'development' into 'master'

Development

See merge request !8
This commit is contained in:
Li Jianxuan 2015-05-03 10:43:35 +08:00
commit 5abff99764
3 changed files with 25 additions and 20 deletions

View File

@ -2,6 +2,7 @@
namespace Westdc\Db;
use Westdc\Helpers\Assist as view;
use Westdc\Helpers\Assist;
class Dbh
{
@ -24,7 +25,7 @@ class Dbh
foreach($data as $k=>$v)
{
$fields[] = '"'.$k.'"';
if(is_int($v) || is_float($v) || is_bool($v))
if(is_int($v) || is_float($v) || is_bool($v) || $v === "NULL")
{
$datas[] = $v;
}else{
@ -81,7 +82,7 @@ class Dbh
foreach($data as $k=>$v)
{
if(is_int($v) || is_float($v) || is_bool($v))
if(is_int($v) || is_float($v) || is_bool($v) || $v === "NULL")
{
$ups[] = '"'.$k.'"='.$v;
}else{
@ -122,6 +123,7 @@ class Dbh
}
}else{
$sql = "UPDATE \"".$table."\" SET $fields $wheresql RETURNING id";
//exit($sql);
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
@ -136,7 +138,7 @@ class Dbh
{
return false;
}else{
echo view::Dump('Caught exception: '. $e->getMessage(). "\n"."SQL:".$sql,false);
echo Assist::Dump('Caught exception: '. $e->getMessage(). "\n"."SQL:".$sql,false);
}
}
}

View File

@ -83,9 +83,22 @@ class Record extends AbstractEventManager {
$id = $dbh->update($table,$data,$where,true);
}
elseif($where instanceof Sql\Where)
elseif($where instanceof Sql\Where || is_callable($where))
{
try{
$adapter = Db::getInstance();
$sql = new Sql\Sql($adapter);
$update = $sql->update($table);
$update->where($where);
$update->set($data);
$statement = $sql->prepareStatementForSqlObject($update);
return $statement->execute();
}catch (\Exception $e){
throw new RecordException($e->getMessage(),$e->getCode());
}
}
elseif(is_array($where))

View File

@ -112,7 +112,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac
$this->makeDateDir();
if(empty($this->fileName) || empty($fileName))
if(empty($this->fileName) && empty($fileName))
$this->setFileName(NULL , $fileService->getFileTextExt($files['name']));
if(!empty($fileName))
@ -289,24 +289,14 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac
*/
public function setFileName($fileName,$fileExt = "")
{
if(!empty($fileName)){
if(empty($fileExt))
{
$fileExt = pathinfo($fileName,PATHINFO_EXTENSION);
}
if(empty($fileExt))
$this->fileName = $fileName;
else
$this->fileName = $fileName . "." .$fileExt;
return;
}
$tools = $this->serviceManager->get('Tools');
$this->fileUuid = $uuid = $tools->uuid();
if(!empty($fileName)){
$this->fileName = $fileName;
return;
}
if(empty($fileExt))
$this->fileName = $uuid;
else