Skip to content

Commit a00618c

Browse files
committed
Update docs for Postgres and MySQL modules
1 parent 3ad381b commit a00618c

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ChatScript MySQL
2+
3+
© Bruce Wilcox, mailto:gowilcox@gmail.com www.brilligunderstanding.com
4+
<br>Revision 6/25/2017 cs7.51
5+
6+
## Using MySQL as file server
7+
8+
One can also use MySQL as a replacement for the local file system of the USERS directory.
9+
This allows you to scale CS horizontally by having multiple CS servers all connecting to
10+
a common MySQL machine so a user can be routed to any server. To do this, on the ChatScript
11+
command line provide the following command line params:
12+
```
13+
mysqlhost=127.0.0.1 mysqlport=3306 mysqldb=chatscript mysqluser=chatuser mysqlpasswd=password
14+
```
15+
It's probably easier to put these 5 params in a config file and use the config= command line param.
16+
17+
The MySQL code assumes the userfiles table exists in the database. You can create a database and
18+
the userfiles table using the following statements:
19+
```
20+
create database chatscript character set 'UTF8';
21+
create user chatuser identified by 'password';
22+
grant all on chatscript.* to chatuser;
23+
use chatscript;
24+
create table userfiles (userid varchar(400) PRIMARY KEY, file blob);
25+
```
26+
27+
The MySQL code uses the following prepared statement queries to read, insert, and update a user record:
28+
```
29+
-- read a user
30+
SELECT file FROM userfiles WHERE userid = ?
31+
-- insert a user
32+
INSERT INTO userfiles (file, userid) VALUES (?, ?)
33+
-- update a user
34+
UPDATE userfiles SET file = ? WHERE userid = ?
35+
```
36+
37+
You can override these queries to support alternate schemas. However, the MySQL module
38+
assumes that any sql used to override the default queries will use the same sequence of arguments.
39+
For example, assume you want to store user data in a table named 'randomusertable.' The following
40+
parameters can be used to override the default MySQL queries:
41+
```
42+
mysqluserread=SELECT userdata FROM randomusertable WHERE username=?
43+
mysqluserinsert=INSERT INTO randomusertable (userdata,username) VALUES (?, ?)
44+
mysqluserupdate=UPDATE randomusertable SET userdata = ? WHERE username = ?
45+
```
46+
47+
Note that the default and override queries use the same arguments in the same order.

WIKI/ESOTERIC-CHATSCRIPT/ChatScript-PostgreSQL.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,38 @@ Each user will get an entry in the userfiles table.
4141
If Postgres is not available, the CS server will quit. Hopefully you have an automatic restart cron job and
4242
it will be able to connect to Postgres the next time.
4343

44+
### Update 2017-10-04
45+
46+
You can now specify the name of the postgres db:
47+
```
48+
pguser="dbname = mydb host = 129.22.22.24 port = 5432 user = postgres password = somepassword "
49+
```
50+
51+
If the dbname is specified, the postgres module will not try to create a new database or a userfiles table.
52+
If dbname is not specified, the postgres module will provide its original behavior.
53+
54+
The postgres code uses the following parameter queries to read, insert, and update a user record:
55+
```
56+
-- read a user
57+
SELECT file FROM userfiles WHERE userid = $1::varchar ;
58+
-- insert a user
59+
INSERT INTO userfiles (file, userid) VALUES ($1::bytea, $2::varchar) ;
60+
-- update a user
61+
UPDATE userfiles SET file = $1::bytea WHERE userid = $2::varchar ;
62+
```
63+
64+
You can override these queries to support alternate schemas. However, the postgres module
65+
assumes that any sql used to override the default queries will use the same sequence of arguments.
66+
For example, assume you want to store user data in a table named 'randomusertable.' The following
67+
parameters can be used to override the default postgres SQL:
68+
```
69+
pguserread=SELECT userdata FROM randomusertable WHERE username=$1::varchar ;
70+
pguserinsert=INSERT INTO randomusertable (userdata,username) VALUES ($1::bytea, $2::varchar) ;
71+
pguserupdate=UPDATE randomusertable SET userdata = $1::bytea WHERE username = $2::varchar ;
72+
```
73+
74+
Note that the default and override queries use the same arguments in the same order.
75+
4476

4577
## Access A PostgreSQL Database
4678

0 commit comments

Comments
 (0)