


================== Informix installation ========================

- CentOS 7

- As root 

yum update

reboot

- As root 

- Install Informix with defaults http://smooth1.co.uk/installs/dbinstalls.html#4.4.2

- usermod -d /home/informix informix

- mkdir /home/informix

- chown informix:informix /home/informix

- cp /root/.bash_profile /home/informix

- chown informix:informix /home/informix/.bash_profile

- Add to /home/informix/.bash_profile

. /opt/IDS.12.10.FC8/ol_informix1210.ksh

export LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:/usr/lib 

=============== SQL ====================================================
CREATE DATABASE justdave
CONNECT TO 'justdave';
CREATE TABLE client ( client_id INT,client_name CHAR(50),client_age INT);
INSERT INTO client (client_id,client_name,client_age) VALUES(1,'justdave',20);
INSERT INTO client (client_id,client_name,client_age) VALUES(2,'red rose',30);
INSERT INTO client (client_id,client_name,client_age) VALUES(3,NULL,NULL);
SELECT * FROM client;
UPDATE client SET client_name='white rose' WHERE client_name='red rose';
DELETE FROM client WHERE client_name='justdave';
SELECT * FROM client;

-- BSON

SELECT genbson( ROW(client_id,client_name,client_age))::JSON FROM client;
-- allow NULL columns, omit id  
SELECT genbson( ROW(client_id,client_name,client_age),1,1)::JSON FROM client;

CREATE TABLE client_bson (client_id INT, client_details BSON);
INSERT INTO client_bson 
SELECT client_id, genbson( ROW(client_name,client_age),1,1) FROM client;

SELECT client_id, client_details::JSON client_details FROM client_bson;

-- JSON
CREATE TABLE client_json (client_id INT, client_details JSON);
INSERT INTO client_json 
SELECT client_id, genbson( ROW(client_name,client_age),1,1)::JSON FROM client;

SELECT * FROM client_json;
UNLOAD TO /tmp/1 SELECT * FROM client_json;

TRUNCATE TABLE client_json;

LOAD FROM /tmp/1 INSERT INTO client_json;
SELECT * FROM client_json;

-- BSON functions
SELECT client_id, client_details::JSON client_details FROM client_bson;

SELECT client_id, 
bson_get(client_details,"client_age")::json,
BSON_VALUE_INT(client_details,"client_age") FROM client_bson;

SELECT client_id, BSON_VALUE_INT(client_details,"client_age") FROM client_bson;

UPDATE client_bson
 SET client_details = '{"client_name":"yellow rose","client_age":30}'::JSON::BSON  
 WHERE BSON_GET(client_details,"client_name") = '{"client_name":"white rose"}'::JSON::BSON;

UPDATE client_bson 
  SET client_details = '{"client_name":"yellow rose","client_age":30}'::JSON::BSON  
  WHERE BSON_GET(client_details,"client_name") = 
 '{"client_name":"white rose"}'::JSON::BSON;

SELECT client_id, client_details::JSON client_details FROM client_bson;

CREATE INDEX cb1 ON client_bson(BSON_GET(client_details, "client_name")) USING BSON;

=============== SPL ====================================================

-- spl1
CREATE PROCEDURE spl_1()

TRUNCATE TABLE client;

INSERT INTO client (client_id,client_name,client_age) VALUES(1,'justdave',20);
INSERT INTO client (client_id,client_name,client_age) VALUES(2,'red rose',30);
INSERT INTO client (client_id,client_name,client_age) VALUES(3,NULL,NULL);

END PROCEDURE;

EXECUTE PROCEDURE spl_1();
SELECT * FROM client;

-- spl2
CREATE PROCEDURE spl_2()

DEFINE cl_id INT;
DEFINE cl_name CHAR(50);
DEFINE cl_age INT;

FOREACH cur1 FOR 
 SELECT client_id,client_name,client_age 
 INTO cl_id,cl_name,cl_age 
 FROM client
  IF (cl_name = 'red rose') THEN
    UPDATE client SET client_name='white rose' WHERE CURRENT OF cur1;
    CONTINUE FOREACH;
  END IF
  IF (cl_name = 'justdave') THEN
    DELETE FROM client WHERE CURRENT OF cur1;
    CONTINUE FOREACH;
  END IF
END FOREACH

END PROCEDURE;

EXECUTE PROCEDURE spl_2();
SELECT * FROM client;

-- spl3
CREATE PROCEDURE spl_3()
RETURNING INT,JSON,INT;

DEFINE cl_id INT;
DEFINE cl_details JSON;
DEFINE cl_age INT;

FOREACH cur1 FOR 
 SELECT client_id, 
 bson_get(client_details,"client_age")::json,
 BSON_VALUE_INT(client_details,"client_age") 
 INTO cl_id,cl_details,cl_age
 FROM client_bson
 
 RETURN cl_id,cl_details,cl_age WITH RESUME;
END FOREACH

END PROCEDURE;

EXECUTE PROCEDURE spl_3();


-------------- x4GL ---------------------


MAIN 

DEFINE cl_id INT
DEFINE cl_name CHAR(50)
DEFINE cl_age INT

DECLARE cur1 CURSOR FOR
 SELECT client_id,client_name,client_age 
 FROM client

FOREACH cur1 INTO cl_id,cl_name,cl_age 
  IF (cl_name = 'red rose') THEN
    UPDATE client SET client_name='white rose' WHERE CURRENT OF cur1
    CONTINUE FOREACH
  END IF
  IF (cl_name = 'justdave') THEN
    DELETE FROM client WHERE CURRENT OF cur1
    CONTINUE FOREACH
  END IF
END FOREACH
  
END MAIN

-------------- Perl ---------------------

yum install perl-ExtUtils-Embed
yum install perl-ExtUtils-MakeMaker

cd /home/informix/tools/PERL/DBD-Informix-2015.1101
. /opt/IDS.12.10.FC8/ol_informix1210.ksh 
export LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:/usr/lib

perl Makefile.PL
make
make test
make install


-------------- PHP ---------------------

https://www.ibm.com/developerworks/data/library/techarticle/dm-0606bombardier/

wget http://www.php.net/distributions/php-7.1.4.tar.gz
wget http://apache.osuosl.org/httpd/httpd-2.4.25.tar.gz
wget https://pecl.php.net/get/PDO_INFORMIX-1.3.3.tgz

wget http://download.nextag.com/apache//apr/apr-1.5.2.tar.gz
wget http://download.nextag.com/apache//apr/apr-util-1.5.4.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre2-10.23.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz

tar xzf httpd-2.4.25.tar.gz
tar xzf PDO_INFORMIX-1.3.3.tgz
tar xzf php-7.1.4.tar.gz
tar xzf pcre2-10.23.tar.gz
tar xzf pcre-8.40.tar.gz

-- from http://apr.apache.org
tar xzf apr-1.5.2.tar.gz
tar xzf apr-util-1.5.4.tar.gz

cd /usr/local/src/apr-1.5.2
./configure
make
make install

cd /usr/local/src/apr-util-1.5.4
./configure --with-apr=/usr/local/apr/ --with-crypto --with-openssl=/usr/local/ssl
make 
make install

cd /usr/local/src/pcre2-10.23
./configure
make
make install

cd /usr/local/src/pcre-8.40
./configure
make
make install

cd /usr/local/src/httpd-2.4.25/

./configure \
--prefix=/usr/local/apache \
--enable-shared=max \
--enable-module=rewrite \
--enable-module=so \
--with-apr=/usr/local/apr/

make
make install

vim /usr/local/apache/conf/httpd.conf
Add:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

cd /usr/local/src/php-7.1.4/ext
cp -R ../../PDO_INFORMIX-1.3.3 pdo_informix

cd /usr/local/src/php-7.1.4

yum install libxml2-devel

./buildconf --force

./configure --with-apxs2=/usr/local/apache/bin/apxs \
--disable-debug \
--disable-ftp \
--disable-inline-optimization \
--disable-magic-quotes \
--disable-mbstring \
--enable-wddx=shared \
--enable-xml \
--with-dom \
--with-regex=system \
--with-xml \
--with-jpeg-dir=/usr/lib \
--with-zlib-dir=/usr/lib \
--with-zlib \
--without-pdo-sqlite \
--without-iconv \
--without-sqlite \
--enable-shared \
--enable-pdo \
--with-pdo-informix=/opt/IDS.12.10.FC8

make
make install

cp php.ini-development /usr/local/lib/php.ini

php -m 

should include PDO and pdo_informix modules

. /opt/IDS.12.10.FC8/ol_informix1210.ksh 
/usr/local/apache/bin/apachectl start

mv /usr/local/apache/htdocs/index.html /usr/local/apache/htdocs/index.html2
vim /usr/local/apache/htdocs/index.php

Add

<html>
<body>
<?php
echo "PHP and Apache are playing nicely!";
?>
</body>
</html>

Run browser with http://localhost/index.php

#
# Create OS user
#
useradd testuser
passwd testuser # testpass

#
# setup table
#
echo "grant dba to testuser" | dbaccess justdave
echo "create table test_table (name char(20))" | dbaccess justdave
echo "insert into test_table values ("JUSTDAVE")" | dbaccess justdave

echo "grant dba to testuser" | dbaccess stores_demo
echo "create table test_table (name char(20))" | dbaccess stores_demo
echo "insert into test_table values ("JUSTDAVE")" | dbaccess stores_demo

-- query table
vim /usr/local/apache/htdocs/query.php

Run browser with http://localhost/query.php

vim /usr/local/apache/htdocs/query2.php

Run browser with http://localhost/query2.php

vim /usr/local/apache/htdocs/query3.php

Run browser with http://localhost/query3.php

-- insert rows
vim /usr/local/apache/htdocs/insert.php

Run browser with http://localhost/insert.php
Run browser with http://localhost/query.php

-- prepared update and direct delete
vim /usr/local/apache/htdocs/updel.php

Run browser with http://localhost/updel.php
Run browser with http://localhost/query.php

vim /usr/local/apache/htdocs/commit.php

Run browser with http://localhost/commit.php

vim /usr/local/apache/htdocs/error.php

Run browser with http://localhost/error.php

php error.php # Command line!


================= Python ===============================

https://wiki.python.org/moin/Informix

http://informixdb.sourceforge.net/

https://sourceforge.net/projects/informixdb/ -> Files -> informixdb -> 

https://sourceforge.net/projects/informixdb/files/informixdb/InformixDB-2.5/

-> InformixDB-2.5.tar.gz

cd /usr/local/src
tar xzf InformixDB-2.5.tar.gz

cd InformixDB-2.5/

yum install python-devel

python setup.py build_ext
python setup.py install

python

import informixdb
conn = informixdb.connect('justdave@ol_informix1210', user='testuser', password='testpass')
cursor = conn.cursor()
cursor.execute('TRUNCATE TABLE test_table')
cursor.execute('INSERT INTO test_table VALUES(:1)', ('justdave',))
cursor.execute('INSERT INTO test_table VALUES(:1)', ('FIRST NAME',))
cursor.execute('INSERT INTO test_table VALUES(:1)', ('SECOND NAME',))
cursor.execute("SELECT * FROM test_table")
cursor.fetchall()
cursor.execute('UPDATE test_table SET name=:1 WHERE name=:2', ('first name', 'FIRST NAME'))
cursor.execute('DELETE FROM test_table WHERE name="SECOND NAME"')
cursor.rowcount
cursor.execute("SELECT * FROM test_table")
cursor.description
cursor.description[0][1]
cursor.fetchall()

import informixdb
conn = informixdb.connect('stores_demo@ol_informix1210', user='testuser', password='testpass')
cursor = conn.cursor()
cursor.execute('TRUNCATE TABLE test_table')
conn.commit()
cursor.execute('INSERT INTO test_table VALUES(:1)', ('justdave',))
conn.commit()
cursor.execute('INSERT INTO test_table VALUES(:1)', ('FIRST NAME',))
conn.rollback()
try:
	cursor.execute('SLECT name FROM test_table2')
except informixdb.DatabaseError, e:
	print "Error"
	print e
	print "action ",e.action
	print "sqlcode ",e.sqlcode
	print "diagnostics ",e.diagnostics

print "Done"
print "version",informixdb.version
print "dbms_name",conn.dbms_name
print "dbms_version",conn.dbms_version
print "driver_name",conn.driver_name
print "driver_version",conn.driver_version


================= Ruby on Rails ===============================

yum install gcc-c++ patch readline readline-devel zlib zlib-devel
yum install libyaml-devel libffi-devel openssl-devel make
yum install bzip2 autoconf automake libtool bison iconv-devel sqlite-devel

curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -L get.rvm.io | bash -s stable

source /etc/profile.d/rvm.sh
rvm reload

rvm requirements run
rvm install 2.2.4
rvm use 2.2.4 --default
ruby --version

gem install activerecord-informix-adapter

================= .NET ===============================

Install Visual Studio 2015 Community Edition
Install .NET Framework 3.5
Install Informix Client SDK

Run Informix ClientSDK ConnectTest demo as Adminstrator

Open firewall port on CentOS for the Informix server

firewall-cmd --zone=public --add-port=23177/tcp --permanent
firewall-cmd --reload 

https://www.ibm.com/developerworks/data/library/techarticle/dm-0510durity/

File->New-Project->Visual C#->Console Application



Add

using IBM.Data.Informix;

Add

    string ConnectionString = "Host=192.168.96.135; " +
     "Service=23177; " +
     "Server=demoinf; " +
     "Database=justdave; " +
     "User Id=informix; " +
     "Password=Derff1234; ";
    //Can add other DB parameters here like DELIMIDENT, DB_LOCALE etc
    //Full list in Client SDK's .Net Provider Reference Guide p 3:13
    IfxConnection conn = new IfxConnection();
    conn.ConnectionString = ConnectionString;
    try {
        conn.Open();
        Console.WriteLine("Made connection!");
        Console.ReadLine();
    } catch (IfxException ex) {
        Console.WriteLine("Problem with connection attempt: "
                          + ex.Message);
    }


Build->Configuration manager->In Grid change select Platform dropdown, New -> x64 copy from Any Cpu
Build->Build Solution
Click on Start

Add


================= Java ===============================

cd /opt/IDS.12.10.FC8/jdbc/demo/basic

export CLASSPATH=/opt/IDS.12.10.FC8/jdbc/demo/basic:/opt/IDS.12.10.FC8/jdbc/lib/ifxjdbc.jar:/opt/IDS.12.10.FC8/jdbc/lib/ifxlang.jar
java SimpleConnection 'jdbc:informix-sqli://localhost6:23176:user=testuser;password=testpass'

# Debugging
# http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
# Down and install JDK for Linux x86_64
# mkdir /tmp/y
# cd /tmp/y
# tar xzf /home/informix/Downloads/jdk-8u131-linux-x64.tar.gz
# export CLASSPATH=/tmp/y:/opt/IDS.12.10.FC8/jdbc/lib/ifxjdbc.jar:/opt/IDS.12.10.FC8/jdbc/lib/ifxlang.jar
# jdk1.8.0_131/bin/javac SimpleConnection.java
# jdk1.8.0_131/bin/java SimpleConnection 'jdbc:informix-sqli://localhost6:23176:user=testuser;password=testpass'

================= C ===============================

This is ESQL/C

onparams -a -d datadbs -s 20000
onparams -a -d datadbs -s 20000
onparams -a -d datadbs -s 20000

dbaccessdemo stores_demo
Answer N at prompt to copy examples to the current directory

cd /opt/IDS.12.10.FC8/demo/esqlc
make dyn_sql
./dyn_sql
select * from customer

