help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple Mysql access for Mac OS X


From: joel3000
Subject: Simple Mysql access for Mac OS X
Date: Tue, 2 Jun 2009 13:54:40 -0700 (PDT)

Hi all,

Total octave newb here. I was having problems getting the database package
to install on my x86 mac. Not having a lot of time to screw around with it I
came up with a very simple way to access a mysql database.

This is not an efficient, robust or particularly good way to access the
database, BUT it works if you just need to get something done quick and the
database package is giving you install troubles.

This function takes as an input a SQL command and returns a numeric matrix
by way of the mysql command line interface and the file system, i.e. it's
ugly. It won't work for alphabetic data. 



function out = usql(sql)
        unlink "foo.out"
        # edit the cmd line as follows:
        # -u<user_name> -p<password> -D<database>
        cmd = sprintf("mysql -umy_name -pmy_pass -Dmy_db --execute '%s'
--skip-column-name > foo.out",sql)
        system(cmd)
        out=load 'foo.out'
endfunction

Example usage: out = usql("SELECT a,b FROM table WHERE a > 3")

out will have contain an nx2 matrix of the output. 


Hope this helps someone.

Best,

Joel Bremson, MS
Graduate Student Researcher
UC Davis
-- 
View this message in context: 
http://www.nabble.com/Simple-Mysql-access-for-Mac-OS-X-tp23840638p23840638.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]