Re: How do I execute a sql-file inside D code

2019-08-26 Thread Anders S via Digitalmars-d-learn

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 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


I'm using MariaDB on std port 3306
/a




Re: How do I execute a sql-file inside D code

2019-08-26 Thread Anders S via Digitalmars-d-learn

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


Re: How do I execute a sql-file inside D code

2019-08-22 Thread XavierAP via Digitalmars-d-learn

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


Re: How do I execute a sql-file inside D code

2019-08-20 Thread Andre Pany via Digitalmars-d-learn

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


How do I execute a sql-file inside D code

2019-08-20 Thread Anders S via Digitalmars-d-learn
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 ?