diff options
author | Richard Knight <q@1bpm.net> | 2020-03-17 18:47:36 +0000 |
---|---|---|
committer | Richard Knight <q@1bpm.net> | 2020-03-17 18:47:36 +0000 |
commit | c3853f6dd796615f332fefcaaaf563794d867ee4 (patch) | |
tree | be3aa506a3631e9261a68894a9fad26ccd911f80 /examples/5-mysql-basic.csd | |
download | csound-sqldb-c3853f6dd796615f332fefcaaaf563794d867ee4.tar.gz csound-sqldb-c3853f6dd796615f332fefcaaaf563794d867ee4.tar.bz2 csound-sqldb-c3853f6dd796615f332fefcaaaf563794d867ee4.zip |
initial
Diffstat (limited to 'examples/5-mysql-basic.csd')
-rw-r--r-- | examples/5-mysql-basic.csd | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/examples/5-mysql-basic.csd b/examples/5-mysql-basic.csd new file mode 100644 index 0000000..bf8e857 --- /dev/null +++ b/examples/5-mysql-basic.csd @@ -0,0 +1,110 @@ +<CsoundSynthesizer> +<CsOptions> +-odac +</CsOptions> +<CsInstruments> +/* + EXAMPLE 3 + + Run some queries on a MySQL database using just inbuilt functions and system tables + + +*/ + +sr = 44100 +kr = 4410 +nchnls = 2 +0dbfs = 1 +seed 0 + + +; connect: type, hostname or IP, database name, username, password +gidb dbconnect "mysql", "hostname", "databasename", "user", "password" + + +; print a random float from the database +instr execscalar + ires dbscalar gidb, "SELECT RAND()" + print ires +endin + + +; print the current_timestamp from the database +instr execscalarstr + Sres dbscalar gidb, "SELECT CONCAT(NOW(), '\n')" + prints Sres +endin + + +; print some float columns from the database activity statistics table +instr execarray + Sql = {{ + SELECT INDEX_LENGTH, AVG_ROW_LENGTH, TABLE_ROWS + FROM INFORMATION_SCHEMA.TABLES + LIMIT 10 + }} + ires[][] dbarray gidb, Sql + printarray ires +endin + + +; print some string columns from the database activity table +instr execarraystr + Sql = {{ + SELECT TABLE_NAME, TABLE_COMMENT, ROW_FORMAT + FROM INFORMATION_SCHEMA.TABLES + LIMIT 10 + }} + Sres[][] dbarray gidb, Sql + irow = 0 + + ; loop through as printarray does not support multidimensional string arrays + while (irow < lenarray(Sres)) do + icol = 0 + while (icol < 3) do + Sitem sprintf "%d, %d : %s\n", irow, icol, Sres[irow][icol] + prints Sitem + icol += 1 + od + irow += 1 + od + +endin + + +; print the current_timestamp from the database server twice per second, and print when the query has been executed +instr execscalar_k + ktrigger metro 2 + kdone, Sres dbscalar_k gidb, "SELECT CONCAT('now = ', NOW(), '\n')", ktrigger + if (kdone == 1) then + printks "%s", 0, Sres + endif +endin + + +; print 2x2 random floats from the database every second +instr execarray_k + ktrigger metro 1 + kdone, kres[][] dbarray_k gidb, "SELECT RAND(), RAND() UNION SELECT RAND(), RAND()", ktrigger + if (kdone == 1) then + printk2 kres[0][0] + printk2 kres[0][1] + printk2 kres[1][0] + printk2 kres[1][1] + endif + +endin + + +</CsInstruments> +<CsScore> + +i "execscalar" 0 1 +i "execscalarstr" 2 1 +i "execarray" 4 1 +i "execarraystr" 6 1 +i "execscalar_k" 7 5 +i "execarray_k" 12 5 + +</CsScore> +</CsoundSynthesizer>
\ No newline at end of file |