go to: HOME, MESSAGES or EXAMPLES_EXTENDED
EXAMPLES
The following example allow simple test between the SQLite, MySQL/MariaDB and Postgres Databases (see: t/testFirst.t)
NOTE: For more examples see test modules (t/testSQL.t, t/testWhere.t and t/testDB.t) in source code.
To test you need:
(a) Create a temporary database, as described below (SQLite, MySQL, MariaDB or Postgres);
(b) Copy/Past the Source Code and;
(c) Make the test.
Create SQLite Database
# sqlite3 -batch -echo /tmp/test_db.db <<EOF
CREATE TABLE master (
i_m_id integer primary key autoincrement,
s_m_code text,
s_m_name text,
s_m_desc text
);
CREATE TABLE slave (
i_s_id integer primary key autoincrement,
s_m_code text,
s_s_code text,
s_s_name text,
s_s_desc text
);
EOF
Create MySQL/MariaDB Database
# mysql -v <<EOF
CREATE SCHEMA IF NOT EXISTS test_db DEFAULT CHARACTER SET 'UTF8' ;
USE test_db ;
CREATE TABLE IF NOT EXISTS test_db.master
(
i_m_id int auto_increment unique,
s_m_code varchar(32),
s_m_name varchar(255),
s_m_desc varchar(255)
) ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS test_db.slave
(
i_s_id int auto_increment unique,
s_m_code varchar(32),
s_s_code varchar(32),
s_s_name varchar(255),
s_s_desc varchar(255)
) ENGINE = InnoDB;
CREATE USER 'user_read'@'localhost' IDENTIFIED BY 'password_read';
CREATE USER 'user_update'@'localhost' IDENTIFIED BY 'password_update';
GRANT SELECT ON test_db.* TO 'user_read'@'localhost';
GRANT SELECT,INSERT,UPDATE,DELETE ON test_db.* TO 'user_update'@'localhost';
EOF
Create Postgres Database
Step1 - creating the database
# psql -U postgres <<EOF
CREATE DATABASE test_db ENCODING 'UTF8';
EOF
Step2 - creating tables and rules
# psql -U postgres -b test_db <<EOF
CREATE SCHEMA IF NOT EXISTS test_schema ;
CREATE TABLE IF NOT EXISTS test_schema.master
(
i_m_id smallserial unique,
s_m_code varchar(32),
s_m_name varchar(255),
s_m_desc varchar(255)
);
CREATE TABLE IF NOT EXISTS test_schema.slave
(
i_s_id smallserial unique,
s_m_code varchar(32),
s_s_code varchar(32),
s_s_name varchar(255),
s_s_desc varchar(255)
);
CREATE ROLE user_read LOGIN PASSWORD 'password_read';
CREATE ROLE user_update LOGIN PASSWORD 'password_update';
GRANT SELECT ON TABLE
test_schema.master, test_schema.slave TO user_read;
GRANT SELECT,INSERT,UPDATE,DELETE ON TABLE
test_schema.master, test_schema.slave TO user_update;
EOF
Source Code
NOTE: Copy and Paste the following lines, until END:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
Testing
# perl /tmp/my_first_program.pl -driver=sqlite
ok 1 - Number of 11 successful (master+slave), Code 0000
ok 2 - Number of 11 successful (master+slave), Code 0001
ok 3 - Number of 11 successful (master+slave), Code 0002
ok 4 - Number of 11 successful (master+slave), Code 0003
ok 5 - Number of 11 successful (master+slave), Code 0004
ok 6 - Number of 11 successful (master+slave), Code 0005
ok 7 - Number of 11 successful (master+slave), Code 0006
ok 8 - Number of 11 successful (master+slave), Code 0007
ok 9 - Number of 11 successful (master+slave), Code 0008
ok 10 - Number of 11 successful (master+slave), Code 0009
ok 11 - Master select, rows 10
ok 12 - Slave select, rows 100
ok 13 - Master/Slave merge-1, rows 1000
ok 14 - Master/Slave merge-2, rows 100
ok 15 - Master/Slave merge-3, rows 900
1..15
# perl /tmp/my_first_program.pl -driver=mysql
ok 1 - Number of 11 successful (master+slave), Code 0000
ok 2 - Number of 11 successful (master+slave), Code 0001
ok 3 - Number of 11 successful (master+slave), Code 0002
ok 4 - Number of 11 successful (master+slave), Code 0003
ok 5 - Number of 11 successful (master+slave), Code 0004
ok 6 - Number of 11 successful (master+slave), Code 0005
ok 7 - Number of 11 successful (master+slave), Code 0006
ok 8 - Number of 11 successful (master+slave), Code 0007
ok 9 - Number of 11 successful (master+slave), Code 0008
ok 10 - Number of 11 successful (master+slave), Code 0009
ok 11 - Master select, rows 10
ok 12 - Slave select, rows 100
ok 13 - Master/Slave merge-1, rows 1000
ok 14 - Master/Slave merge-2, rows 100
ok 15 - Master/Slave merge-3, rows 900
1..15
# perl /tmp/my_first_program.pl -driver=postgres
ok 1 - Number of 11 successful (master+slave), Code 0000
ok 2 - Number of 11 successful (master+slave), Code 0001
ok 3 - Number of 11 successful (master+slave), Code 0002
ok 4 - Number of 11 successful (master+slave), Code 0003
ok 5 - Number of 11 successful (master+slave), Code 0004
ok 6 - Number of 11 successful (master+slave), Code 0005
ok 7 - Number of 11 successful (master+slave), Code 0006
ok 8 - Number of 11 successful (master+slave), Code 0007
ok 9 - Number of 11 successful (master+slave), Code 0008
ok 10 - Number of 11 successful (master+slave), Code 0009
ok 11 - Master select, rows 10
ok 12 - Slave select, rows 100
ok 13 - Master/Slave merge-1, rows 1000
ok 14 - Master/Slave merge-2, rows 100
ok 15 - Master/Slave merge-3, rows 900
1..15
ENDED