-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.m
executable file
·82 lines (80 loc) · 3.13 KB
/
mysql.m
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
% MYSQL - Interact with a MySQL database server
%
% INSTALL SNOW LEOPARD - Run in Matlab - mex -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient mysql.cpp
% If no output arguments are given on the left, then display results.
% If arguments are given, then return requested data silently.
%
% mysql( 'open', host, user, password )
% Open a connection with specified parameters, or defaults if none
% host: default is local host. Use colon for port number
% user: default is Unix login name.
% password: default says connect without password.
%
% Examples: mysql('open','arkiv') % connect on default port
% mysql('open','arkiv:2215')
%
% If successful, open returns the new connection handle.
% If unsuccessful, it throws an error and returns nothing.
%
% mysql('close')
% Close the current connection
%
% mysql('use',db) or mysql('use db')
% Set the current database to db Example: mysql('use cme')
%
% mysql('status')
% Display information about the connection and the server.
% Return 0 if connection is open and functioning
% 1 if connection is closed
% 2 if should be open but we cannot ping the server
%
% mysql( query )
% Send the given query or command to the MySQL server
%
% If arguments are given on the left, then each argument
% is set to the column of the returned query.
% Dates and times in result are converted to Matlab format:
% dates are serial day number, and times are fraction of day.
% String variables are returned as cell arrays.
%
% Example:
% [ t, p ] = mysql('select time,price,askbid from cme.sp
% where date="1997-04-30" and expir like "1997-06-%"');
% (but be sure to put quoted text all on one input line)
% Returns time and price for trades on the June 1997 contract
% that occured on April 30, 1997.
%
% All string comparisons are case-insensitive
%
% Multiple connections: The program can maintain up to 10
% independent connections. Any command may be preceded by a
% connection handle -- an integer from 0 to 9 -- to apply the
% command to that connection.
% Example:
% mysql(5,'open','host2') % connection 5 to host 2
% mysql % status of all connections
%
% If no connection handle is given then
% an OPEN statement will find an unused handle
% and return the value
% any other statement will use the most recently
% used handle. When the current connection is closed,
% "most recent" reverts to its previous value.
%
% This permits nested constructions of the form
%
% mysql('open','data1',...)
% mysql('use something')
% mysql('do something')
%
% perhaps inside another .m file
% mysql('open','data2',...)
% ...
% mysql('close')
%
% mysql('do something else to data1')
% mysql('close')
%
% The special command 'closeall' closes all open connections
% The special case 'mysql' or 'mysql()' with no arguments
% shows status of all open connections (returns nothing).