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