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 | |
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
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | create/oracle/schema.sql | 2 | ||||
-rw-r--r-- | frontends/php/config.php | 2 | ||||
-rw-r--r-- | frontends/php/image.php | 5 | ||||
-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 | ||||
-rw-r--r-- | frontends/php/map.php | 9 |
8 files changed, 148 insertions, 37 deletions
@@ -1,5 +1,6 @@ Changes for 1.1beta11: + - fixed image storing for oracle (Eugene) - eliminated function DBaffected_rows() (Alexei) - new function DBselectN() to select N records only. (Alexei) - fixed graph duplication (Eugene) diff --git a/create/oracle/schema.sql b/create/oracle/schema.sql index 7e6ac6d4..4b4d59a9 100644 --- a/create/oracle/schema.sql +++ b/create/oracle/schema.sql @@ -1013,7 +1013,7 @@ CREATE TABLE images ( imageid number(10) NOT NULL, imagetype number(10) DEFAULT '0' NOT NULL, name varchar2(64) DEFAULT '0' NOT NULL, - image varchar2(2048) DEFAULT NULL, + image BLOB, CONSTRAINT images PRIMARY KEY (imageid) ); diff --git a/frontends/php/config.php b/frontends/php/config.php index dd83c084..12674c51 100644 --- a/frontends/php/config.php +++ b/frontends/php/config.php @@ -432,7 +432,7 @@ $table=new CTableInfo(S_NO_IMAGES_DEFINED); $table->setHeader(array(S_ID,S_NAME,S_TYPE,S_IMAGE)); - $result=DBselect("select imageid,imagetype,name,image from images order by name"); + $result=DBselect("select imageid,imagetype,name from images order by name"); while($row=DBfetch($result)) { if($row["imagetype"]==1) $imagetype=S_ICON; diff --git a/frontends/php/image.php b/frontends/php/image.php index c4d3bca2..8cadcd8c 100644 --- a/frontends/php/image.php +++ b/frontends/php/image.php @@ -51,8 +51,9 @@ $th_height = get_request("height",0); } - $result=DBselect("select image from images where imageid=".$_REQUEST["imageid"]); - $row=DBfetch($result); + //$result=DBselect("select image from images where imageid=".$_REQUEST["imageid"]); + //$row=DBfetch($result); + $row = get_image_by_imageid($_REQUEST["imageid"]); if($row["image"] == "") exit; 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) diff --git a/frontends/php/map.php b/frontends/php/map.php index 56f74d69..b6198eee 100644 --- a/frontends/php/map.php +++ b/frontends/php/map.php @@ -83,13 +83,10 @@ $x=imagesx($im); $y=imagesy($im); -# ImageFilledRectangle($im,0,0,$width,$height,$black); + ImageFilledRectangle($im,0,0,$width,$height,$white); if($background!="") { - $db_images = DBselect("select image from images". - " where imagetype=2 and name=".zbx_dbstr($background)); - - $db_image = DBfetch($db_images); + $db_image = get_image_by_name($background, 2); if($db_image) { $back = ImageCreateFromString($db_image["image"]); @@ -97,14 +94,12 @@ } else { - ImageFilledRectangle($im,0,0,$width,$height,$white); $x=imagesx($im)/2-ImageFontWidth(4)*strlen($name)/2; ImageString($im, 4,$x,1, $name , $darkred); } } else { - ImageFilledRectangle($im,0,0,$width,$height,$white); $x=imagesx($im)/2-ImageFontWidth(4)*strlen($name)/2; ImageString($im, 4,$x,1, $name , $colors["Dark Red"]); } |