ghkweon / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Cant create Database object #411

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When compiling following script (using also TdwsHtmlFilter, thus the "<?pas"):

<?pas

var db := DataBase.Create('UIB', ['localhost:myDB','foo','bar']);
var query := db.Query('select F from T', []);

?>

Warning: Constructor invoked on instance outside of constructor [line: 3, 
column: 20]
Syntax Error: Too many arguments [line: 3, column: 20]
Syntax Error: There is no accessible member with name "Query" [line: 4, column: 
17]

Basically it's the example code in wiki but instead of SQLite I want to use 
Firebird via UIB driver.

Original issue reported on code.google.com by ain.val...@gmail.com on 3 Jun 2013 at 11:50

GoogleCodeExporter commented 8 years ago
Hmmm, do you have a TdwsDatabaseLib component and its Script property set to 
the TDelphiWebScript? Other possibility could be if you have something else 
named "DataBase" in your code.

Other than these two, could you make a sample that reproduces the issue?

Original comment by zar...@gmail.com on 3 Jun 2013 at 3:40

GoogleCodeExporter commented 8 years ago
I didn't have the TdwsDatabaseLib component! However, I now create one (I 
create all components in code): 

  FDBLib := TdwsDatabaseLib.Create(nil);
  FDBLib.Script := FDWS;

in my scripting support code now. Is thats all what is needed or I'm still 
missing something as it still doesn't work - while it compiles now without 
error, only "start" is in the output for the script:

print('start');
var db := DataBase.Create('UIB', ['localhost:myDB','foo','bar']);
print('db created');
var query := db.Query('select ClientIP, Rem_Prc from LOG_InOut', []);

Original comment by ain.val...@gmail.com on 3 Jun 2013 at 4:08

GoogleCodeExporter commented 8 years ago
You probably have error messages in your execution (check Exec.Msgs.AsInfo f.i.)

Do you have the UIB driver unit (dwsUIBDatabase) in your "uses" on the Delphi 
side? Otherwise the UIB driver won't be register and accesible in script.

Original comment by zar...@gmail.com on 4 Jun 2013 at 6:30

GoogleCodeExporter commented 8 years ago
That was it, I had to include the dwsUIBDatabase in the uses! It is working 
now, so the issue could be closed, but I suggest to add that info also into the 
wiki page, something like:

In order to use the DataBase object in a script the TDelphiWebScript must be 
connected to an TdwsDatabaseLib component and appropriate driver units 
(dwsUIBDatabase for the "UIB" driver, dwsSynSQLiteDatabase for the "SQLLite" 
driver etc) must be used by the host program.

Original comment by ain.val...@gmail.com on 4 Jun 2013 at 7:51

GoogleCodeExporter commented 8 years ago
Updated wiki

Original comment by zar...@gmail.com on 4 Jun 2013 at 9:49