Documentation for pp_lib

Generated by IDLdoc

single page | use frames     summary     class     fields     routine details     file attributes

./

pp_structtomysql.pro


Author information

Author

Paulo Penteado (http://www.ppenteado.net), Apr/2015

Routines

Routines from pp_structtomysql.pro

result = pp_structtomysql__typename(var [, minlen=minlen] [, maxlen=maxlen])

Helper function, to return the mysql variable type corresponding to an IDL variable type.

pp_structtomysql, struct, tablename, dbname=string [, username=string] [, verbose=verbose] [, primary_key=string] [, nodeletecsv=nodeletecsv] [, nodroptable=nodroptable] [, generate_code_only=generate_code_only]

Creates a table in a mysql server, from an IDL array of structures.

Routine details

top source pp_structtomysql__typename

result = pp_structtomysql__typename(var [, minlen=minlen] [, maxlen=maxlen])

Helper function, to return the mysql variable type corresponding to an IDL variable type.

Parameters

var in required

The IDL variable whose mysql type is desired.

Keywords

minlen in optional

If the type is a string, by default the mysql type will have the length of the longest string in var. If minlen is provided, the mysql length will be the greatest among minlen and the longest string in var.

maxlen in optional

If the type is a string, by default the mysql type will have the length of the longest string in var. If maxlen is provided, the mysql length will be the smallest among maxlen and the longest string in var.

Author information

Author:

Paulo Penteado (http://www.ppenteado.net), Apr 2015

Statistics

Lines:
26 lines
Cyclomatic complexity:
14
Modified cyclomatic complexity:
4

top source pp_structtomysql

pp_structtomysql, struct, tablename, dbname=string [, username=string] [, verbose=verbose] [, primary_key=string] [, nodeletecsv=nodeletecsv] [, nodroptable=nodroptable] [, generate_code_only=generate_code_only]

Creates a table in a mysql server, from an IDL array of structures. Each element of the array becomes a row in the table. The column names are the structure field names, with a '_' appended (to avoid mysql reserved words). The mysql server information (address, login, password, etc) is taken from ~/.my.conf. This is handled by Marc Buie's openmysql (http://www.boulder.swri.edu/~buie/idl/pro/openmysql.html).

Parameters

struct in required

The structure containing the data to be inserted in the mysql table.

tablename in required type=string

The name of the table to be created.

Keywords

dbname in required type=string

The name of the database where the table is to be created.

username in optional type=string

The username to use in mysql. Defaults to the current user.

verbose in optional

If set, the mysql commands get printed to the terminal.

primary_key in optional type=string

If set, determines which key will be the table's primary key.

nodeletecsv in optional

During injection, the data is put into a csv file in the current directory (pp_structtomysql_tmpfile.csv). If this keyword is set, the file is not deleted at the end.

nodroptable in optional

By default, if the table to be created already exists, it is dropped, then created with the data provided. If this keyword is set, dropping the table is skipped, and this procedure will just attempt to insert the data into the table.

generate_code_only out optional

If provided, this variable will contain a string array with the commands that would have been issued to mysql. No mysql commands are executed.

Examples

Create a table in a mysql server (server parameters set in ~/.my.conf), then retrieve the data from it. In this case, assuming that there is a database named pp_structtomysql, and that the user has write access to it:

outstruct=replicate({a:1,b:2d0,c:'def'},4) outstruct.a=indgen(4) outstruct.b=dindgen(4)^2 outstruct.c+='_'+strtrim(indgen(4),2) print,outstruct ;{ 0 0.0000000 def_0} ;{ 1 1.0000000 def_1} ;{ 2 4.0000000 def_2} ;{ 3 9.0000000 def_3} pp_structtomysql,outstruct,'pp_structtomysql_example',primary_key='c_',dbname='pp_structtomysql' openmysql,lun,'pp_structtomysql' instruct=pp_mysqlquery(lun,'select * from pp_structtomysql_example;') print,instruct ;{ 0 0 def_0} ;{ 1 1 def_1} ;{ 2 4 def_2} ;{ 3 9 def_3} free_lun,lun

Author information

Author:

Paulo Penteado (http://www.ppenteado.net), Apr 2015

Other attributes

Requires:

openmysql, mysqlquery, from Marc Buie's library (http://www.boulder.swri.edu/~buie/idl/).

Statistics

Lines:
41 lines
Cyclomatic complexity:
13
Modified cyclomatic complexity:
13

File attributes

Modification date: Wed Jun 29 22:15:28 2016
Lines: 67
Docformat: rst rst