digitalmars.D.learn - How do I execute a sql-file inside D code
- Anders S (10/10) Aug 20 2019 I'm creating an application that connect to a database and write
- Andre Pany (7/17) Aug 20 2019 You need to use an additional library to communicate with the
- Anders S (3/24) Aug 26 2019 I'm using MariaDB on std port 3306
- XavierAP (8/12) Aug 22 2019 I understand you're using some API to some SQL implementation
- Anders S (3/17) Aug 26 2019 Thanks XavierAP, that did the trick
I'm creating an application that connect to a database and write data from another application. Now when I start the application I want it to check if the database exists and if not create the database and it's tables. I have everything working IF the database and tables exist. 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 Any ideas ?
Aug 20 2019
On Tuesday, 20 August 2019 at 11:33:33 UTC, Anders S wrote:I'm creating an application that connect to a database and write data from another application. Now when I start the application I want it to check if the database exists and if not create the database and it's tables. I have everything working IF the database and tables exist. 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 Any ideas ?You need to use an additional library to communicate with the database. The library to use depends on the type of database (Oracle, DB2, sqlite, Hana, postgres,...) Which database type do you target? Kind regards Andre
Aug 20 2019
On Tuesday, 20 August 2019 at 13:10:55 UTC, Andre Pany wrote:On Tuesday, 20 August 2019 at 11:33:33 UTC, Anders S wrote:I'm using MariaDB on std port 3306 /aI'm creating an application that connect to a database and write data from another application. Now when I start the application I want it to check if the database exists and if not create the database and it's tables. I have everything working IF the database and tables exist. 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 Any ideas ?You need to use an additional library to communicate with the database. The library to use depends on the type of database (Oracle, DB2, sqlite, Hana, postgres,...) Which database type do you target? Kind regards Andre
Aug 26 2019
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 folderI 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
Aug 22 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:Thanks XavierAP, that did the trick /aUse 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 folderI 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
Aug 26 2019