I am well aware of the odbc and odbca plugins, which seem to primarily be about retrieving data stored in a database for use in AB. I would like to do the opposite, store data from AB in a database for access by other programs. I understand that this can be done via exporting csv files and then importing them into MariaDB or mySQL, but, as usual, I am looking for the elegant solution. Any ideas?
This function takes string parameter containing valid SQL statement such as INSERT, UPDATE, DELETE, etc., and as such allows write operations on the database. It is not intended to be used with SELECT statements or other statements (stored procedure calls) returning recordsets as it returns only true/false on success/failure.
I used it to export all the quotes of one of my local databases to MS-SQL, and this was a straightforward task.
Using it for other purposes maybe require a more elaborate workflow.
This is what I was referring to when I cited a more elaborate workflow.
It is possible to combine all the available options you have, like writing/exporting your data in a flat file (maybe also using a "Batch" to do it in different steps, allowing you to include optional external scripts/tools) and then, check for specific tables existence and/or to create/purge them as needed via odbcExecuteSQL and finally, as suggested by @Tomasz, create a LOAD DATA INFILE statement and execute it again via ODBC directly from one of your your formulas.
Thanks for the comments. That is exactly what I have been doing. I am in the process of streamlining/automating my daily workflow and looking around for better, more elegant/efficient ways to get it all done.
Tomasz, thanks for AB, a fine tool.
AB community, thanks for all the help.
It didn't seem to make sense to give the import code without the export code, so here it is. Full disclosure, adapted from code found here. (Is that Buy = 0: really needed?)
Good trading,
John
// John Bollinger 29 March 2019
// Copyright Bollinger Capital Management 2019
// MIT License
// export directory
directory = "C:\\Users\\Public\\Portfolio\\exports\\";
// get the symbol
symbol = Name();
// extension to use
extension = ".txt";
// open export file
fh = fopen( directory + symbol + extension, "w" );
if ( fh ) // did we get a file handle?
{
Date_ = DateTime(); // get a list of dates
fputs( "Symbol,Date,Open,High,Low,Close,Volume\n", fh ); // write header
for ( i = 0; i < BarCount; i++ ) // write the data records
{
fputs( symbol + "," , fh ); // symbol
fputs( DateTimeToStr( Date_[ i ] ) + ",", fh ); // date
fputs( StrFormat( "%g,%g,%g,%g,%g\n", open[ i ], high[ i ], low[ i ], close[ i ], volume[ i ] ), fh ); // quotes
}
fclose( fh ); // close the file
}
Buy = 0; // line required by SCAN option
// That's all Folks!