Using the PostgreSQL RDBMS:
http://www.postgresql.org/about/
and the Embedded SQL in C facility:
http://www.postgresql.org/docs/8.2/static/ecpg.html
with the Mumps Compiler:
http://www.cs.uni.edu/~okane
http://cns2.uni.edu/~okane/source/MUMPS-MDH/compiler.html
http://cns2.uni.edu/~okane/source/MUMPS-MDH/mdh.html
It is possible for a Mumps program using the Mumps Compiler
and the MDH toolkit to interact with a PostgreSQL database
server (locally or remotely). The PostgreSQL Embedded SQL
facility will run with the Mumps Compiler. The following
example shows a Mumps program retrieving data from
the server and storing the results in global arrays. Most
SQL commands are supported (see PostgreSQL documentation).
Here follows the command line statements, the Mumps program
and the output of same (all data is randomly created and none
of the names are real). The example is rather SQL and interface
top-heavy but once the data is fetched from the server, any
Mumps activity is possible. Updates back to the database,
including full featured transaction processing, can also be done.
Basically, RDBMS's are nice, but very limited at times when
you're dealing with data that is essentially hierarchical or,
in other words, a varying number of columns per row. Mumps
does these things quite nicely, thanks, and is much faster.
In the following, lines beginning with + are passed by the
Mumps Compiler to the C++ module being generated without
change. The output of 'mumps2c' is 'sql3.cpp' which is then
post-processed by 'ecpg', a program from PostgreSQL,
that processes the EXEC tatements. The output of this
is 'sql3.c' (a C++ program, actually. '.c' is the default and my
'g++' compiler doesn't complain) which is compiled by 'g++'
and linked with the Mumps runtime libraries.
C++ variables of type 'mstring' are linked to the run-time Mumps
symbol table. Any changes to these variables in the C++ program
are reflected as changes to the corresponding variables in
the Mumps program. The use of 'char **' variables is required
by 'ecpg' which will not support the 'mstring' type (macros,
I gather). Some techinical detail: an embedded C++/C statement may
not be the first after a 'for' command nor the first one following
an indented block.
The SQL commands are as per the SQL standard.
..............................................
mumps2c sql3.mps
ecpg sql3.cpp
g++ sql3.c -lmpscpp -lmumps -lmpsglobal_native -lpcre -lecpg -lpq
cat sql3.mps
+ EXEC SQL WHENEVER SQLERROR sqlprint;
zmain
+ mstring Ptid("Ptid");
+ mstring Fname("Fname");
+ mstring Lname("Lname");
+ mstring Date("Date");
+ mstring Time("Time");
+ mstring Test("Test");
+ mstring Result("Result");
write "hello world",!
+ EXEC SQL BEGIN DECLARE SECTION;
+ char **ptid;
+ char **firstname;
+ char **lastname;
+ char **date;
+ char **time;
+ char **test;
+ char **result;
+ EXEC SQL END DECLARE SECTION;
+ EXEC SQL CONNECT TO test@[EMAIL PROTECTED]
EXEC SQL DECLARE DBC1 CURSOR FOR SELECT ptid, namefirst, namelast FROM
ptname;
+ EXEC SQL OPEN DBC1;
for i=1:1 do
. write "Load Patient Demographic ",i,!
+ EXEC SQL FETCH IN DBC1 INTO :ptid, :firstname, :lastname;
+ if (sqlca.sqlcode == ECPG_NOT_FOUND) svPtr->tpx = 0; else svPtr->tpx =
1;
+ Ptid=*ptid;
+ Fname=*firstname;
+ Lname=*lastname;
. if '$test break
. write Ptid," ",Fname," ",Lname,!
. set ^patient(Ptid)=Fname_" "_Lname
write "Done with Demographics",!
+ EXEC SQL CLOSE DBC1;
+ EXEC SQL DECLARE DBC2 CURSOR FOR SELECT ptid, date, time, test, result
FROM labs;
+ EXEC SQL OPEN DBC2;
for i=1:1 do
. write "Load Patient Labs ",i,!
+ EXEC SQL FETCH IN DBC2 INTO :ptid, :date, :time, :test, :result;
+ if (sqlca.sqlcode == ECPG_NOT_FOUND) svPtr->tpx = 0; else svPtr->tpx =
1;
+ Ptid=*ptid;
+ Date=*date;
+ Time=*time;
+ Test=*test;
+ Result=*result;
. if '$test break
. write Ptid," ",Date," ",Test," ",Result,!
. set ^patient(Ptid,Test,Date,Time)=Result
write "Done with Labs",!
+ EXEC SQL DISCONNECT ALL;
a.out
hello world
Load Patient Demographic 1
1001 John Jones
Load Patient Demographic 2
1002 Charles Smith
Load Patient Demographic 3
1003 Sara Smith
Load Patient Demographic 4
1004 Jane Jones
Load Patient Demographic 5
1005 William Adams
Load Patient Demographic 6
Done with Demographics
Load Patient Labs 1
1001 1999-Jul-11 Glucose 10
Load Patient Labs 2
1001 1999-Jul-12 Glucose 12
Load Patient Labs 3
1001 1999-Jul-13 Glucose 14
Load Patient Labs 4
1001 1999-Jul-14 Glucose 16
Load Patient Labs 5
1001 1999-Jul-15 Glucose 18
Load Patient Labs 6
1001 1999-Jul-16 Glucose 20
Load Patient Labs 7
1001 1999-Jul-17 Glucose 22
Load Patient Labs 8
1001 1999-Jul-18 Glucose 24
Load Patient Labs 9
1001 1999-Jul-19 Glucose 16
Load Patient Labs 10
1002 1999-Jul-11 Glucose 10
Load Patient Labs 11
1002 1999-Jul-12 Glucose 12
Load Patient Labs 12
1002 1999-Jul-13 Glucose 14
Load Patient Labs 13
1002 1999-Jul-14 Glucose 16
Load Patient Labs 14
1002 1999-Jul-15 Glucose 18
Load Patient Labs 15
1002 1999-Jul-16 Glucose 20
Load Patient Labs 16
1002 1999-Jul-17 Glucose 22
Load Patient Labs 17
1002 1999-Jul-18 Glucose 24
Load Patient Labs 18
1002 1999-Jul-19 Glucose 16
Load Patient Labs 19
1003 1999-Jul-11 Glucose 10
Load Patient Labs 20
1003 1999-Jul-12 Glucose 12
Load Patient Labs 21
1003 1999-Jul-13 Glucose 14
Load Patient Labs 22
1003 1999-Jul-14 Glucose 16
Load Patient Labs 23
1003 1999-Jul-15 Glucose 18
Load Patient Labs 24
1003 1999-Jul-16 Glucose 20
Load Patient Labs 25
1003 1999-Jul-17 Glucose 22
Load Patient Labs 26
1003 1999-Jul-18 Glucose 24
Load Patient Labs 27
1003 1999-Jul-19 Glucose 16
Load Patient Labs 28
1004 1999-Jul-11 Glucose 10
Load Patient Labs 29
1004 1999-Jul-12 Glucose 12
Load Patient Labs 30
1004 1999-Jul-13 Glucose 14
Load Patient Labs 31
1004 1999-Jul-14 Glucose 16
Load Patient Labs 32
1004 1999-Jul-15 Glucose 18
Load Patient Labs 33
1004 1999-Jul-16 Glucose 20
Load Patient Labs 34
1004 1999-Jul-17 Glucose 22
Load Patient Labs 35
1004 1999-Jul-18 Glucose 24
Load Patient Labs 36
1004 1999-Jul-19 Glucose 16
Load Patient Labs 37
1005 1999-Jul-11 Glucose 10
Load Patient Labs 38
1005 1999-Jul-12 Glucose 12
Load Patient Labs 39
1005 1999-Jul-13 Glucose 14
Load Patient Labs 40
1005 1999-Jul-14 Glucose 16
Load Patient Labs 41
1005 1999-Jul-15 Glucose 18
Load Patient Labs 42
1005 1999-Jul-16 Glucose 20
Load Patient Labs 43
1005 1999-Jul-17 Glucose 22
Load Patient Labs 44
1005 1999-Jul-18 Glucose 24
Load Patient Labs 45
1005 1999-Jul-19 Glucose 16
Load Patient Labs 46
1001 1999-Jul-11 Hct 10
Load Patient Labs 47
1001 1999-Jul-12 Hct 12
Load Patient Labs 48
1001 1999-Jul-13 Hct 14
Load Patient Labs 49
1001 1999-Jul-14 Hct 16
Load Patient Labs 50
1001 1999-Jul-15 Hct 18
Load Patient Labs 51
1001 1999-Jul-16 Hct 20
Load Patient Labs 52
1001 1999-Jul-17 Hct 22
Load Patient Labs 53
1001 1999-Jul-18 Hct 24
Load Patient Labs 54
1001 1999-Jul-19 Hct 16
Load Patient Labs 55
1002 1999-Jul-11 Hct 10
Load Patient Labs 56
1002 1999-Jul-12 Hct 12
Load Patient Labs 57
1002 1999-Jul-13 Hct 14
Load Patient Labs 58
1002 1999-Jul-14 Hct 16
Load Patient Labs 59
1002 1999-Jul-15 Hct 18
Load Patient Labs 60
1002 1999-Jul-16 Hct 20
Load Patient Labs 61
1002 1999-Jul-17 Hct 22
Load Patient Labs 62
1002 1999-Jul-18 Hct 24
Load Patient Labs 63
1002 1999-Jul-19 Hct 16
Load Patient Labs 64
1003 1999-Jul-11 Hct 10
Load Patient Labs 65
1003 1999-Jul-12 Hct 12
Load Patient Labs 66
1003 1999-Jul-13 Hct 14
Load Patient Labs 67
1003 1999-Jul-14 Hct 16
Load Patient Labs 68
1003 1999-Jul-15 Hct 18
Load Patient Labs 69
1003 1999-Jul-16 Hct 20
Load Patient Labs 70
1003 1999-Jul-17 Hct 22
Load Patient Labs 71
1003 1999-Jul-18 Hct 24
Load Patient Labs 72
1003 1999-Jul-19 Hct 16
Load Patient Labs 73
1004 1999-Jul-11 Hct 10
Load Patient Labs 74
1004 1999-Jul-12 Hct 12
Load Patient Labs 75
1004 1999-Jul-13 Hct 14
Load Patient Labs 76
1004 1999-Jul-14 Hct 16
Load Patient Labs 77
1004 1999-Jul-15 Hct 18
Load Patient Labs 78
1004 1999-Jul-16 Hct 20
Load Patient Labs 79
1004 1999-Jul-17 Hct 22
Load Patient Labs 80
1004 1999-Jul-18 Hct 24
Load Patient Labs 81
1004 1999-Jul-19 Hct 16
Load Patient Labs 82
1005 1999-Jul-11 Hct 10
Load Patient Labs 83
1005 1999-Jul-12 Hct 12
Load Patient Labs 84
1005 1999-Jul-13 Hct 14
Load Patient Labs 85
1005 1999-Jul-14 Hct 16
Load Patient Labs 86
1005 1999-Jul-15 Hct 18
Load Patient Labs 87
1005 1999-Jul-16 Hct 20
Load Patient Labs 88
1005 1999-Jul-17 Hct 22
Load Patient Labs 89
1005 1999-Jul-18 Hct 24
Load Patient Labs 90
1005 1999-Jul-19 Hct 16
Load Patient Labs 91
1001 1999-Jul-11 Hgb 10
Load Patient Labs 92
1001 1999-Jul-12 Hgb 12
Load Patient Labs 93
1001 1999-Jul-13 Hgb 14
Load Patient Labs 94
1001 1999-Jul-14 Hgb 16
Load Patient Labs 95
1001 1999-Jul-15 Hgb 18
Load Patient Labs 96
1001 1999-Jul-16 Hgb 20
Load Patient Labs 97
1001 1999-Jul-17 Hgb 22
Load Patient Labs 98
1001 1999-Jul-18 Hgb 24
Load Patient Labs 99
1001 1999-Jul-19 Hgb 16
Load Patient Labs 100
1002 1999-Jul-11 Hgb 10
Load Patient Labs 101
1002 1999-Jul-12 Hgb 12
Load Patient Labs 102
1002 1999-Jul-13 Hgb 14
Load Patient Labs 103
1002 1999-Jul-14 Hgb 16
Load Patient Labs 104
1002 1999-Jul-15 Hgb 18
Load Patient Labs 105
1002 1999-Jul-16 Hgb 20
Load Patient Labs 106
1002 1999-Jul-17 Hgb 22
Load Patient Labs 107
1002 1999-Jul-18 Hgb 24
Load Patient Labs 108
1002 1999-Jul-19 Hgb 16
Load Patient Labs 109
1003 1999-Jul-11 Hgb 10
Load Patient Labs 110
1003 1999-Jul-12 Hgb 12
Load Patient Labs 111
1003 1999-Jul-13 Hgb 14
Load Patient Labs 112
1003 1999-Jul-14 Hgb 16
Load Patient Labs 113
1003 1999-Jul-15 Hgb 18
Load Patient Labs 114
1003 1999-Jul-16 Hgb 20
Load Patient Labs 115
1003 1999-Jul-17 Hgb 22
Load Patient Labs 116
1003 1999-Jul-18 Hgb 24
Load Patient Labs 117
1003 1999-Jul-19 Hgb 16
Load Patient Labs 118
1004 1999-Jul-11 Hgb 10
Load Patient Labs 119
1004 1999-Jul-12 Hgb 12
Load Patient Labs 120
1004 1999-Jul-13 Hgb 14
Load Patient Labs 121
1004 1999-Jul-14 Hgb 16
Load Patient Labs 122
1004 1999-Jul-15 Hgb 18
Load Patient Labs 123
1004 1999-Jul-16 Hgb 20
Load Patient Labs 124
1004 1999-Jul-17 Hgb 22
Load Patient Labs 125
1004 1999-Jul-18 Hgb 24
Load Patient Labs 126
1004 1999-Jul-19 Hgb 16
Load Patient Labs 127
1005 1999-Jul-11 Hgb 10
Load Patient Labs 128
1005 1999-Jul-12 Hgb 12
Load Patient Labs 129
1005 1999-Jul-13 Hgb 14
Load Patient Labs 130
1005 1999-Jul-14 Hgb 16
Load Patient Labs 131
1005 1999-Jul-15 Hgb 18
Load Patient Labs 132
1005 1999-Jul-16 Hgb 20
Load Patient Labs 133
1005 1999-Jul-17 Hgb 22
Load Patient Labs 134
1005 1999-Jul-18 Hgb 24
Load Patient Labs 135
1005 1999-Jul-19 Hgb 16
Load Patient Labs 136
Done with Labs


|