#1 2013-01-03 10:57:18

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

This is driving me nuts... it already took 2 days of my time.


Using todays mormot checkout, I keep getting this ESQLite3Exception with message "No Error". (Yesterday's version had the same problem)

The exception is raised in the following call stack:

Mormot_D17.SynSQLite3.sqlite3_check(4268688952,21)
Mormot_D17.mORMotSQLite3.TSQLVirtualTableModuleSQLite3.Create(TSQLVirtualTableExternal,$FE6213C0,$FE7BBA20)
Mormot_D17.mORMotSQLite3.TSQLVirtualTableModuleServerDB.Create(TSQLVirtualTableExternal,$FE6213C0)
Mormot_D17.mORMotSQLite3.TSQLRestServerDB.InitializeEngine
Mormot_D17.mORMotSQLite3.TSQLRestServerDB.Create($FE7CB5E0,$FE7BBA20,True)
Mormot_D17.mORMotSQLite3.TSQLRestClientDB.Create($FE7CB5E0,$FE7CB5E0,$FE7BBA20,TSQLRestServerDB,True)
Mormot_D17.mORMotSQLite3.TSQLRestClientDB.Create($FE7CB5E0,$FE7CB5E0,':memory:',TSQLRestServerDB,True,'')
SGMormotTestSuitePkg_D17.uTestMormotDBBaseCommon.TMormotDBBaseCommonTest.SetUp

In order to get the exception I have to
1) Explicitly add TSQLAuthGroup and TSQLAuthUser to my TSQLModel
2) Call VirtualTableExternalRegisterAll(MyModel,Props,FALSE)

When I use VirtualTableExternalRegisterAll(MyModel,Props,TRUE) the error does not occur, obviously because VirtualTableExternalRegister is not called for TSQLAuthGroup and TSQLAuthUser
When I leave out TSQLAuthGroup and TSQLAuthUser the exception is also not raised.

I have a similar problem with my own defined classes, but seem to be unable to pinpoint the cause. I tried debugging into sqlite3.c but that didnt work out because debug info seems to be crippled (unmatching blue bullets/stepping in debugger).

Do you have any idea how to close in on this error? It seems to happen with all engines (Oracle, SQLite3 file, SQLite3 memory and our own NexusDB)

Hans

Offline

#2 2013-01-03 11:23:07

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

I have created a work-around that seems to do the trick. Though I have no idea where the error code 21 (some OS error) actually originates from.

function sqlite3_check(DB: TSQLite3DB; aResult: integer): integer;
VAR ErrMessage:string;
begin
  if (DB=0) or (aResult in [SQLITE_ERROR..SQLITE_ROW-1]) then // possible error codes
  case aResult of
    SQLITE_MISUSE:
    begin
       ErrMessage:=string(sqlite3_errmsg(DB));
       if AnsiSameText(ErrMessage,'not an error') then
         aResult:=0 // HH avoid the NO ERROR exception
       else raise ESQLite3Exception.Create(ErrMessage,aResult);
    end
    else raise ESQLite3Exception.Create(DB,aResult);
  end;
  result := aResult;
end;

What's your opinion on this, can you think of a better solution?

Last edited by h.hasenack (2013-01-03 11:29:40)

Offline

#3 2013-01-03 11:40:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

Your workaround is not enough.

I think this was a regression introduced by http://synopse.info/fossil/info/443f9dd87b

Please try http://synopse.info/fossil/info/ff7b2b84aa
(and http://synopse.info/fossil/info/1bc4fd6407)

Sorry for the issue.

Offline

#4 2013-01-03 11:54:14

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

Tried it, but no joy sad

I put in my workaround and it's OK again. I experienced this problem also with an older mormot version when I updated the sqlite3.obj files. Maybe the issue is caused there somewhere: I I also get some BCC32 compiler warnings. Here they are:

Generate 32bit OBJ files
Embarcadero C++ 6.50 for Win32 Copyright (c) 1993-2012 Embarcadero Technologies, Inc.
sqlite3.c:
Warning W8057 sqlite3.c 50241: Parameter 'pBt' is never used in function removeFromSharingList
Warning W8057 sqlite3.c 56448: Parameter 'p' is never used in function sqlite3BtreeSchemaLocked
Warning W8060 sqlite3.c 101978: Possibly incorrect assignment in function sqlite3_declare_vtab
Warning W8060 sqlite3.c 133710: Possibly incorrect assignment in function nodeAcquire
Warning W8060 sqlite3.c 135498: Possibly incorrect assignment in function SplitNode
Warning W8060 sqlite3.c 136357: Possibly incorrect assignment in function rtreeInit
Embarcadero C++ 6.50 for Win32 Copyright (c) 1993-2012 Embarcadero Technologies, Inc.
sqlite3.c:
Warning W8057 sqlite3.c 50241: Parameter 'pBt' is never used in function removeFromSharingList
Warning W8057 sqlite3.c 56448: Parameter 'p' is never used in function sqlite3BtreeSchemaLocked
Warning W8060 sqlite3.c 101978: Possibly incorrect assignment in function sqlite3_declare_vtab
Warning W8060 sqlite3.c 133710: Possibly incorrect assignment in function nodeAcquire
Warning W8060 sqlite3.c 135498: Possibly incorrect assignment in function SplitNode
Warning W8060 sqlite3.c 136357: Possibly incorrect assignment in function rtreeInit
DONE!
Press any key to continue . . .

I think "Possibly incorrect assignment in function sqlite3_declare_vtab" is definitely suspicious in this case.

Last edited by h.hasenack (2013-01-03 12:17:55)

Offline

#5 2013-01-03 12:49:17

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

very, very likely

  if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){

I can see why the compiler complains, but

  if( !db->pVtabCtx || !(pTab == db->pVtabCtx->pTab) ){

would not fix it because pTab has not been initialized yet...

It's very likely though, that the error is generated here because the TRUE evamulation leads to the SQLITE_MISUSE (21) error

  if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
    sqlite3Error(db, SQLITE_MISUSE, 0);
    sqlite3_mutex_leave(db->mutex);
    return SQLITE_MISUSE_BKPT;
  }

Offline

#6 2013-01-03 13:10:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

Offline

#7 2013-01-03 13:38:18

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

COuld be. I think it's beyond my current knowledge of SQLite. I just took a quick look at the source to see what the warning was about.

I hope you can come up with a test that demononstrates the error and fixes it smile
Typically to reproduce the error you'd have to
1) Register the TSQLAuth tables as external virtual tables
2) start a TSQLRestServer with autorization enabled

This will generate the error when the restserver actually tries to add the virtual table modules to the SQLite3 engine. (well, on XE3/Update it works like that. DOnt know about other delphi releases.)

Regards - Hans

Offline

#8 2013-01-03 15:14:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

I created the Project14ServerExternal.dpr new Sample, and was able to reproduce the issue.

There was a problem in mORMotSQLite3.pas, which registered the same module several times.
Up to now, there was no issue, but SQlite3 seems to check it by now, so it began to raise "SQLITE_MISUSE" - but not in the exact place you highlighted above.

Should be fixed with http://synopse.info/fossil/info/8428623cf5

Offline

#9 2013-01-03 15:36:22

h.hasenack
Member
From: Nijmegen, Netherlands
Registered: 2012-08-01
Posts: 173
Website

Re: Error: No Error , related VirtualTableExternalRegisterAll and TSQLAuth

Yay! will try!

* UPDATE *

I Tried, and all my unit tests turn up green.

Thanks!

Last edited by h.hasenack (2013-01-04 07:44:46)

Offline

Board footer

Powered by FluxBB