database informix

Gianni Pederiva pederiva.g@atm.to.it
Tue, 11 Dec 2001 12:44:38 +0100


---------------------- multipart/alternative attachment
I have downloaded horde 1.2.6 but it doesn't work with informix =
database. I have modified horde/scripts/database/ifmx_create.sql and =
horde/imp/lib/db.informix and, with length of some column shorter, now =
works.=20

Gianni Pederiva

horde/scripts/database/ifmx_create.sql:
-- script to create the necessary Informix database and tables
-- you can simply run this file in dbacces

-- change the database and table names to whatever you'd like
-- them to be - just make sure the IMP config matches.

-- create the database
CREATE DATABASE horde;

-- now connect to the new database
database horde;

-- create the sessions table
CREATE TABLE active_sessions (
  sid varchar(32) DEFAULT '' NOT NULL,
  name varchar(32) DEFAULT '' NOT NULL,
  val text,
  changed varchar(14) DEFAULT '' NOT NULL,
  PRIMARY KEY (name,sid)
);
create index CHANGED on ACTIVE_SESSIONS (CHANGED asc);

-- create the address table
CREATE TABLE imp_addr (
  impuser varchar(40),
  address varchar(200),
  nickname varchar(255),
  fullname varchar(255),
  PRIMARY KEY (impuser,address)
);


-- now create the pref table
CREATE TABLE imp_pref (
  impuser varchar(40),
  sig text,
  replyto varchar(170),
  fullname varchar(170),
  PRIMARY KEY (impuser)
);


--grant all'utente con cui gira apache
grant dba to http;

-- done!

horde/imp/lib/db.informix :

<?php

/* This file is (c) 1998 Juraj Bednar. Any comments to =
<bednar@isternet.sk> */
/* STATE : This file _MAY_ work, it has been completely untested... */

/* Table Structure for Informix version:
  =20
   Preferences Table:
    field:     type:      description:
    impuser    varchar    joe@imap.doe.com format username
    sig        text       signature
    replyto    varchar    joe@doe.com address
    fullname   varchar    Joe Doe
    (possibly more to be added later)
=20
   Address Table:
    field:     type:      description:
    impuser    varchar    joe@doe.com identifier of who this entry =
belongs to
    address    varchar    address@mail.server.com - the actual address
    nickname   varchar    any entered nickname - ie "bonnie".
    fullname   varchar    full name - "My Bonnie".
*/

function imp_add_address ($address, $nickname, $fullname, $user, =
$server) {
   global $default;
  =20
   /* post: adds $address, $nickname, $fullname to the addressbook for =
$user@$server
    returns true on success and false on failure
    */
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query("delete from $default->db_address_table =
where impuser=3D'$user@$server' and address=3D'$address'", $db))) { =
return false; }
   if (!($result =3D ifx_query("insert into $default->db_address_table =
values ('$user@$server', '$address', '$nickname', '$fullname')", $db))) =
{ return false; }
  =20
   return true;
}

function imp_check_prefs($user,$server) {
 global $_imp_prefs_exist, $default;
 if (isset($_imp_prefs_exist)) {
  return $_imp_prefs_exist;
 }
=20
 /* Checks for the presence of a row in prefs table for =
impuser=3D'$user@$server' */
 if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { $_imp_prefs_exist =3D false; }
 elseif (!($result =3D ifx_query("select impuser from =
$default->db_pref_table where impuser=3D'$user@$server'", $db))) { =
$_imp_prefs_exist =3D false; }
 else {
  $row =3D ifx_fetch_row ($result, "NEXT");
  if ($row)=20
   $_imp_prefs_exist =3D true;
  else
   $_imp_prefs_exist =3D false;
 }
=20
 return $_imp_prefs_exist;
}

function imp_delete_address ($address, $user, $server) {
   global $default;
  =20
   /* post: deletes $address from the addressbook of $user@$server
    returns true on success and false on failure
    */
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query("delete from $default->db_address_table =
where impuser=3D'$user@$server' and address=3D'$address'", $db))) { =
return false; }
  =20
   return true;
}

function imp_get_addresses ($user, $server) {
   global $default;
  =20
   /* post: returns a 2d array of addresses where each
    element is an array in which element 0 is the address,
    element 1 is the nickname, and element 2 is the fullname.
    it returns false on failure.
    */
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   // if (!($result =3D ifx_query($db, "select address, nickname, =
fullname from $default->db_address_table where impuser=3D'$user@$server' =
order by nickname"))) { return false; }
   if (!($result =3D ifx_query("select address, nickname, fullname from =
$default->db_address_table where impuser=3D'$user@$server' order by =
nickname", $db))) { return false; }
   if (($rowcount =3D ifx_affected_rows($result))=3D=3D0) { return =
false; }
   for ($i=3D0; $row =3D ifx_fetch_row ($result, "NEXT"); $i++) {
      $rec_contacts[0]=3D$row["address"];  =20
      $rec_contacts[1]=3D$row["nickname"];  =20
      $rec_contacts[2]=3D$row["fullname"];  =20
      $return[$i]=3D$rec_contacts;
   }
  =20
   return($return);
}

function imp_get_from ($user, $server) {
   global $default;
   if (imp_check_prefs($user, $server)) {
 if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return "$user@$server"; }=20
 if (!($result =3D ifx_query("select replyto from =
$default->db_pref_table where impuser=3D'$user@$server'", $db))) { =
return "$user@$server"; }
   $row =3D ifx_fetch_row ($result, "NEXT");
   if ($row) {
 return $row["replyto"];=20
   }
   else
   return "$user@$server";
   }
}

function imp_get_fullname ($user, $server) {
   global $default;
  =20
   /* post: returns the fullname for the database key $user@$server
    (a string), or false on failure.
    */
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query("select fullname from =
$default->db_pref_table where impuser=3D'$user@$server'", $db))) { =
return false; }
  =20
   $row =3D ifx_fetch_row ($result, "NEXT");
   if ($row) {
 return $row["fullname"];=20
   }
   else
     return false;
}

function imp_get_lang ($user, $server) {
   return false;
}

function imp_get_signature ($user, $server) {
   global $default;
  =20
   /* post: returns the signature for the database key $user@$server
    (a string), or false on failure.
    */
  =20
   ifx_textasvarchar(0);
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query("select sig from $default->db_pref_table =
where impuser=3D'$user@$server'", $db))) { return false; }
  =20
   /* $row =3D ifx_fetch_row ($result, "NEXT");=20
   if ($row) return $row[0]; */
   if($data =3D @ifx_fetch_row($result)) {
 return ifx_get_blob($data["sig"]);
   }
   else
     return false;
}

function imp_set_from ($from, $user, $server) {
   global $default;
  =20
   /* post: sets the replyto to $from for the database key $user@$server
    returns true on success and false on failure
    */
   if (imp_check_prefs($user, $server)) {
      $sql =3D "update $default->db_pref_table set replyto=3D'$from' =
where impuser=3D'$user@$server'";
   } else {
      $sql =3D "insert into $default->db_pref_table (impuser, replyto) =
values ('$user@$server', '$from')";
   }
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query($sql, $db))) { return false; }
   global $_imp_prefs_exist;
   $_imp_prefs_exist =3D true;
   return true;
}

function imp_set_fullname ($fullname, $user, $server) {
   global $default;
  =20
   /* post: sets the fullname to $fullname for the database key =
$user@$server
    returns true on success and false on failure
    */
   if (imp_check_prefs($user, $server)) {
      $sql =3D "update $default->db_pref_table set =
fullname=3D'$fullname' where impuser=3D'$user@$server'";
   } else {
      $sql =3D "insert into $default->db_pref_table (impuser, fullname) =
values ('$user@$server', '$fullname')";
   }
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query($sql, $db))) { return false; }
  =20
   global $_imp_prefs_exist;
   $_imp_prefs_exist =3D true;
   return true;
}

function imp_set_lang ($lang, $user, $server) {
   return true;
}

function imp_set_signature ($signature, $user, $server) {
   global $default;
  =20
   /* post: sets the signature to $signature for the database key =
$user@$server
    returns true on success and false on failure
    */
   $blobid =3D ifx_create_blob(1,0,0);
   $blobidary[] =3D $blobid;
   ifx_update_blob($blobid,$signature);
  =20
   if (imp_check_prefs($user, $server)) {
      $sql =3D "update $default->db_pref_table set sig=3D? where =
impuser=3D'$user@$server'";
   } else {
      $sql =3D "insert into $default->db_pref_table (impuser, sig) =
values ('$user@$server', ?)";
   }
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query($sql, $db, $blobidary))) { return false; =
}=20
  =20
   global $_imp_prefs_exist;
   $_imp_prefs_exist =3D true;
   return true;
}

function imp_update_address ($old_address, $address, $nickname, =
$fullname, $user, $server) {
   global $default;
  =20
   /* post: changes the entry for $old_address to $address, $nickname, =
$fullname.
    returns true on success and false on failure
    */
  =20
   if (!($db=3Difx_pconnect ($default->db_name, $default->db_user_name, =
$default->db_password))) { return false; }
   if (!($result =3D ifx_query("update $default->db_address_table set =
address=3D'$address', nickname=3D'$nickname', fullname=3D'$fullname' =
where impuser=3D'$user@$server' and address=3D'$old_address'", $db))) { =
return false; }
  =20
   return true;
}

?>


---------------------- multipart/alternative attachment--