diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-05-23 14:04:50 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-05-23 14:04:50 +0000 |
| commit | 026ee8a0f799dc8faec5bf4ce591746d06795b23 (patch) | |
| tree | faf519f6f76d14bdd24155e4495f44c590850ce6 /frontends/php/include | |
| parent | 90c8eec0c0e5e610b7ba83c1ba46e598f0d060e2 (diff) | |
| download | zabbix-026ee8a0f799dc8faec5bf4ce591746d06795b23.tar.gz zabbix-026ee8a0f799dc8faec5bf4ce591746d06795b23.tar.xz zabbix-026ee8a0f799dc8faec5bf4ce591746d06795b23.zip | |
- fixed image storing for oracle (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2884 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/config.inc.php | 156 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/maps.inc.php | 8 |
3 files changed, 140 insertions, 26 deletions
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index bbe2e755..85c80692 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -366,21 +366,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!! return "$priorities,$md5sum"; } - function get_image_by_name($imagetype,$name) - { - $sql="select * from images where imagetype=$imagetype and name=".zbx_dbstr($name); - $result=DBselect($sql); - $row=DBfetch($result); - if($row) - { - return $row; - } - else - { - return 0; - } - } - function get_function_by_functionid($functionid) { $sql="select * from functions where functionid=$functionid"; @@ -1106,8 +1091,56 @@ COpt::profiling_start("page"); return $table; } + function get_image_by_name($name,$imagetype=NULL) + { + global $DB_TYPE; + + $sql="select image from images where name=".zbx_dbstr($name); + if(isset($imagetype)) + $sql .= "and imagetype=".$imagetype; + + $result=DBselect($sql); + $row=DBfetch($result); + if($row) + { + if($DB_TYPE == "ORACLE") + { + $row['image'] = $row['image']->load(); + } + + return $row; + } + else + { + return 0; + } + } + + function get_image_by_imageid($imageid) + { + global $DB_TYPE; + + $result=DBselect('select * from images where imageid='.$imageid); + $row=DBfetch($result); + if($row) + { + if($DB_TYPE == "ORACLE") + { + $row['image'] = $row['image']->load(); + } + return $row; + } + else + { + return 0; + } + } + function add_image($name,$imagetype,$file) { + global $DB_TYPE; + global $DB; + if(!is_null($file)) { if($file["error"] != 0 || $file["size"]==0) @@ -1118,24 +1151,66 @@ COpt::profiling_start("page"); if($file["size"]<1024*1024) { $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"])); - $sql="insert into images (name,imagetype,image) values (".zbx_dbstr($name).",$imagetype,".zbx_dbstr($image).")"; + if($DB_TYPE == "ORACLE") + { + $lobimage = OCINewDescriptor($DB, OCI_D_LOB); + + $sql = "insert into images (name,imagetype,image)". + " values (".zbx_dbstr($name).",".$imagetype.",EMPTY_BLOB())". + " return image into :image"; + $stid = OCIParse($DB, $sql); + if(!$stid) + { + $e = ocierror($stid); + error("Parse SQL error [".$e["message"]."] in [".$e["sqltext"]."]"); + return false; + } + + OCIBindByName($stid, ':image', $lobimage, -1, OCI_B_BLOB); + + $result = OCIExecute($stid, OCI_DEFAULT); + if(!$result){ + $e = ocierror($stid); + error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]"); + return false; + } + + if ($lobimage->save($image)) { + OCICommit($DB); + } + else { + OCIRollback($DB); + error("Couldn't save image!\n"); + return false; + } + + $lobimage->free(); + OCIFreeStatement($stid); + + return $stid; + } + $sql = "insert into images (name,imagetype,image)". + " values (".zbx_dbstr($name).",".$imagetype.",".zbx_dbstr($image).")"; return DBexecute($sql); } else { error("Image size must be less than 1Mb"); - return FALSE; + return false; } } else { error("Select image to download"); - return FALSE; + return false; } } function update_image($imageid,$name,$imagetype,$file) { + global $DB_TYPE; + global $DB; + if(!is_null($file)) { if($file["error"] != 0 || $file["size"]==0) @@ -1146,7 +1221,50 @@ COpt::profiling_start("page"); if($file["size"]<1024*1024) { $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"])); - $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).",image=".zbx_dbstr($image)." where imageid=$imageid"; + + if($DB_TYPE == "ORACLE") + { + + $result = DBexecute("update images set name=".zbx_dbstr($name). + ",imagetype=".zbx_dbstr($imagetype). + " where imageid=$imageid"); + + if(!$result) return $result; + + $stid = OCIParse($DB, "select image from images where imageid=".$imageid." for update"); + + $result = OCIExecute($stid, OCI_DEFAULT); + if(!$result){ + $e = ocierror($stid); + error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]"); + OCIRollback($DB); + return false; + } + + $row = DBfetch($stid); + + $lobimage = $row['image']; + +// if (!($lobimage->erase())) +// { +// OCIRollback($DB); +// error("Failed to truncate LOB\n"); +// return false; +// } + + if (!$lobimage->save($image)) { + OCIRollback($DB); + } else { + OCICommit($DB); + } + + $lobimage->free(); + + return $stid; + } + + $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype). + ",image=".zbx_dbstr($image)." where imageid=$imageid"; return DBexecute($sql); } else diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 7ca86f4f..1ac62e2b 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -1438,7 +1438,7 @@ if(isset($_REQUEST["imageid"])) { - $result=DBselect("select imageid,imagetype,name,image from images". + $result=DBselect("select imageid,imagetype,name from images". " where imageid=".$_REQUEST["imageid"]); $row=DBfetch($result); diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php index cb394fe8..831dbeab 100644 --- a/frontends/php/include/maps.inc.php +++ b/frontends/php/include/maps.inc.php @@ -238,13 +238,9 @@ else $icon = $element["icon"]; - $images = DBselect("select image from images where imagetype=1 and name=".zbx_dbstr($icon)); - if(!$images) return FALSE; - - $image = DBfetch($images); + $image = get_image_by_name($icon); if(!$image) return FALSE; - - return imagecreatefromstring($image["image"]); + return imagecreatefromstring($image['image']); } function get_info_by_selementid($selementid, &$out_info, &$out_color) |
