How do I execute a sql-file inside D code

Anders S anders at xore.se
Mon Aug 26 13:29:57 UTC 2019


On Thursday, 22 August 2019 at 13:39:00 UTC, XavierAP wrote:
> On Tuesday, 20 August 2019 at 11:33:33 UTC, Anders S wrote:
>>
>> Use this code to check
>> conn.exec("CREATE DATABASE IF NOT EXISTS boxweb;");
>>
>> however haven't found a way to run the sql file that create 
>> the tables. The file is in the source folder
>
> I understand you're using some API to some SQL implementation 
> which allows you to run SQL commands from strings, but not from 
> files which is what you want?
>
> Just read the file into a string with the D std lib:
>
>     import std:file;
>     conn.exec( readText(fileName) );
>
> https://dlang.org/phobos/std_file.html#.readText

Thanks XavierAP, that did the trick
/a


More information about the Digitalmars-d-learn mailing list