1 | % MYM - Interact with a MySQL database server |
---|
2 | % Copyright 2005, EPFL (Yannick Maret) |
---|
3 | % |
---|
4 | % Copyright notice: this code is a heavily modified version of the original |
---|
5 | % work of Robert Almgren from University of Toronto. |
---|
6 | % |
---|
7 | % If no output arguments are given, then display results. Otherwise returns |
---|
8 | % requested data silently. |
---|
9 | % mym() or mym |
---|
10 | % ------------ |
---|
11 | % shows status of all open connections (returns nothing). |
---|
12 | % mym('open', host, user, password) |
---|
13 | % --------------------------------- |
---|
14 | % Open a connection with specified parameters, or defaults if none |
---|
15 | % host: default is local host. Use colon for port number |
---|
16 | % user: default is Unix login name. |
---|
17 | % password: default says connect without password. |
---|
18 | % Examples: mym('open','arkiv') % connect on default port |
---|
19 | % mym('open','arkiv:2215') |
---|
20 | % If successful, open returns 0 if successful, and throw an error |
---|
21 | % otherwise. The program can maintain up to 20 independent connections. |
---|
22 | % Any command may be preceded by a connection handle -- an integer from 0 |
---|
23 | % to 10 -- to apply the command to that connection. |
---|
24 | % Examples: mym(5,'open','host2') % connection 5 to host 2 |
---|
25 | % mym % status of all connections |
---|
26 | % When no connection handle is given, mym use 0 by default. If the |
---|
27 | % corresponding connection is open, it is closed and opened again. |
---|
28 | % It is possible to ask mym to look for an available connection |
---|
29 | % handle by using -1. The used connection handle is then returned. |
---|
30 | % Example: cid = mym(-1, 'open', 'host2') % cid contains the used |
---|
31 | % connection handle |
---|
32 | % mym('close') |
---|
33 | % ------------ |
---|
34 | % Close the current connection. Use mym('closeall') to closes all open |
---|
35 | % connections. |
---|
36 | % mym('use',db) or mym('use db') |
---|
37 | % --------------------------------- |
---|
38 | % Set the current database to db |
---|
39 | % Example: mym('use cme') |
---|
40 | % mym('status') |
---|
41 | % ------------- |
---|
42 | % Display information about the connection and the server. |
---|
43 | % Return 0 if connection is open and functioning |
---|
44 | % 1 if connection is closed |
---|
45 | % 2 if should be open but we cannot ping the server |
---|
46 | % mym(query) |
---|
47 | % ---------- |
---|
48 | % Send the given query or command to the MySQL server. If arguments are |
---|
49 | % given on the left, then each argument is set to the column of the |
---|
50 | % returned query. Dates and times in result are converted to Matlab |
---|
51 | % format: dates are serial day number, and times are fraction of day. |
---|
52 | % String variables are returned as cell arrays. |
---|
53 | % Example: p = mym('select price from contract where date="1997-04-30"'); |
---|
54 | % % Returns price for contract that occured on April 30, 1997. |
---|
55 | % Note: All string comparisons are case-insensitive |
---|
56 | % Placeholders: in a query the following placeholders can be used: {S}, |
---|
57 | % {Si}, {M}, {F}, and {B}. |
---|
58 | % Example: i = 1000; |
---|
59 | % B = [1 2; 3 4]; |
---|
60 | % mym('INSERT INTO test(id,value) VALUES("{Si}","{M}")',i,B); |
---|
61 | % A = mym('SELECT value FROM test WHERE id ="{Si}")', 1000); |
---|
62 | % % Insert the array B into table test with id=1000. Then the |
---|
63 | % % value is retrieved and put into A. |
---|
64 | % {S} is remplaced by a string given by the corresponding argument arg. |
---|
65 | % Arg can be a matlab string or a scalar. The format of the string |
---|
66 | % for double scalars is [sign]d.ddddddEddd; for integers the format |
---|
67 | % is [sign]dddddd. |
---|
68 | % {Sn} is the same as {S} but for double scalar only. The format of the |
---|
69 | % string is [sign]d.ddddEddd, where the number of decimal after the |
---|
70 | % dot is given by n. |
---|
71 | % {Si} is the same as {S} but for double scalar only. The corresponding |
---|
72 | % double is first converted to an integer (using floor). |
---|
73 | % {M} is replaced by the binary representation of the corresponding |
---|
74 | % argument (it can be a scalar, cell, numeric or cell array, or a |
---|
75 | % structure). |
---|
76 | % {B} is replaced by the binary representation of the uint8 vector |
---|
77 | % given in the corresponding argument. |
---|
78 | % {F} is the same as {B} but for the file whose name is given in the |
---|
79 | % corresponding argument. |
---|
80 | % Note: 1) {M}, {B} and {F} need to be put in fields of type BLOB |
---|
81 | % 2) {M}, {B} and {F} binary representations are compressed -- only |
---|
82 | % if the space gain is larger than 10% --. We use zlib v1.2.3! |
---|
83 | % The compression can be switched off by using {uM}, {uB} and |
---|
84 | % {uF}, instead. |
---|
85 | % 3) {M} does not work if the endian of the client used to store |
---|
86 | % the BLOB is different than that used to fetch it. |
---|
87 | % 4) time fields are returned as string dump |
---|
88 | % 5) this kind of insert does not work properly: |
---|
89 | % mym(INSERT INTO tbl(id,txt) VALUES(1000,"abc{dfg}h")'); |
---|
90 | % as the "abc{dfg}h" is mistaken for a mYm command. A possible |
---|
91 | % solution is to use the following command: |
---|
92 | % mym(INSERT INTO tbl(id,txt) VALUES(1000,"{S}")','abc{dfg}h'); |
---|