running an sql script file with llblgen

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 18-Jul-2007 17:06:55   

Hello!

Is it possible to pass an sql script file (ie test.sql) into llbgen and it to run it? This script file may include "GO"s, but it doesn't have to.

This file may be a scripted version of the database which the website wil run on the first use to create the database.

Thanks

Becky

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 18-Jul-2007 20:09:02   

not without some heavy modifications to the code. if you need scripts to run once on install I would make this part of the install process, not the application. the most basic approach would be a bat file to connect to the db, and run a script.

Posts: 1255
Joined: 10-Mar-2006
# Posted on: 19-Jul-2007 03:22:04   

Can you not just derrive a custom IExpression where it just outputs the string you pass in?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Jul-2007 10:13:38   
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 19-Jul-2007 10:30:30   

Thanks Walaa

That's exactly what I want to do..!

Derive a class from DataAccessAdapter, then add a method to that class which calls CreateNewPhysicalConnection, to get a connection object. Using that connection object, you can execute FbCommand objects

Just a quick question though.. will this way of doing it cope with the "GO"s in the scripts or will it fall over like normal .NET database commands do?

I am still only just getting to grips with LLBLGEN so would it be possible that you could give me an example of how I would excecute the command with my connection object?

Thanks in advance

Bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Jul-2007 10:58:03   

The before mentioned approach suggests you use a normal ADO.NET to execute the script, but it shows you how to get a connection object from the DataAccessAdapter to be used in the ADO.NET code.

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 19-Jul-2007 12:05:47   

Ah ok, so I just call the connection object and then use my own code to exceute the cmd.

Would I be able to use this

adapter.ExecuteActionQuery(SQLCOMMAND)

to do anything like that?

I cannot find anything in the documentation about this command, but it seems as if I should just pass this a query and it should do it? like when you pass a stored procedure to CallActionStoredProcedure?

I keep getting, "connection not present" at the moment tho when it definitly is present!

Thanks

Bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Jul-2007 15:36:25   

Would I be able to use this Code: adapter.ExecuteActionQuery(SQLCOMMAND)

to do anything like that?

I cannot find anything in the documentation about this command, but it seems as if I should just pass this a query and it should do it?

Check this out: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7165

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 19-Jul-2007 17:20:14   

Haven't tried this yet, but this blog post looks promising! (along with the advice above about getting a connection object from LLBLGen.)

http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200-Separators-in-SQL-Scripts-_2D00-the-easy-way.aspx

be aware that you might run into a chicken and egg problem if you are trying to create the database that is not built yet using scripts , but specified in the connection string.

Posts: 1255
Joined: 10-Mar-2006
# Posted on: 19-Jul-2007 17:25:41   

Back on the main subject of this thread, it would be nice if the templates did provide a way to execute 'manual sql'.

However, having said that, if you get something working - put it in a template and share with everyone. Maybe then someday, we can talk Otis into including it...

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 19-Jul-2007 17:33:11   

my $.02...

doesn't providing direct sql access defeat the purpose of LLBL? the idea is to provide strongly typed objects to access the db. providing direct sql script access bypasses everything. There is no way to validate the script, so you could run into exceptions at runtime, more so than using LLBL objects.

Posts: 1255
Joined: 10-Mar-2006
# Posted on: 19-Jul-2007 17:39:09   

Yes, it does....but there are situations like the above. Or upgrade database version scripts, etc. Where you actually do need this feature.

tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 19-Jul-2007 21:31:53   

BexMed wrote:

Hello!

Is it possible to pass an sql script file (ie test.sql) into llbgen and it to run it? This script file may include "GO"s, but it doesn't have to.

This file may be a scripted version of the database which the website wil run on the first use to create the database.

Thanks

Becky

Personally, I have an app I wrote to migrate data from one database to a different database with a completely different schema... I created 3 Stored Procs:

  • one to delete the new database
  • one to create the tables, etc.
  • And lastly one to add the relationships and indexes

In LLBLGen, I have those three ActionProcedures that get built in when I generate my db... and then in my code I simply call them... Now if you are talking about random things, this would not work... but in the case of setting up a db first for the site to use, this would work in your situation I believe.

I hope this might be some help...