Recent

Author Topic: Firebird UDF, Error ESQLDatabaseError : 08003 at the second call in the proc  (Read 9857 times)

newbie_fpc

  • New member
  • *
  • Posts: 9
Hi!

I would like to ask some help. In advance, I'm sorry for my english grammar mistakes. So I wrote an UDf for firebird and it is okay at the first call, but at the next call an exception occurs in tha DLL when query.open() or conn.Connected := true or conn.open(), so a connect happens. I have lines for logging and i see that the first call attempt doesnt have any problem, executed successfully, but the next ones.

The exception:
ESQLDatabaseError : 08003 - TIBConnection : DoInternalConnect :
 -connection shutdown

newbie_fpc

  • New member
  • *
  • Posts: 9
I also have tried other Connection classes (TSQLConnector,TIBConnection,TSQLConnection), and each one caused the same. It seems to me, that the problem is with the connection, because if i commented the query.open()/conn.Connected:=true/conn.Open() lines then there is no problem in the UDF. So maybe the connection in the first attempt gets stuck somehow?

newbie_fpc

  • New member
  • *
  • Posts: 9
I forgot these "details":
-Firebird 2.5.8 64bit
-Lazarus 2.0.12
-FPC 3.2.0
-DLL compiled 64bit

korba812

  • Full Member
  • ***
  • Posts: 181
Probably your function in the UDF library triggers an exception that cannot be handled by Firebird, which results in the database connection being dropped.

Wrap your function in try..except block and log exception details:
Code: Pascal  [Select][+][-]
  1. function udf(param: integer): integer;
  2. begin
  3.   try
  4.     ...your code
  5.   except
  6.     on e: exception do
  7.       ... save exception information to file
  8.   end;
  9. end;
  10.  

newbie_fpc

  • New member
  • *
  • Posts: 9
Thank you for your answer.

I've already tried that you suggest and this was the logged exception:

ESQLDatabaseError : 08003 - TIBConnection : DoInternalConnect :
 -connection shutdown

korba812

  • Full Member
  • ***
  • Posts: 181
Are you using SQLDB components in the UDF library and the exception occurs in the UDF library or exception comes from a client application that connects to a Firebird server using the UDF library?

newbie_fpc

  • New member
  • *
  • Posts: 9
Yes. Exception occurs in the DLL when it tries to connect (query.open() or conn.open() or connected := true), ALTOUGH it works at the first attempt, the next try fail with that expection. So I cant understand what is the cause, because then it should not work at the first try when I debug either. I test/debug the UDF running a procedure in IBExpert.
« Last Edit: June 08, 2021, 10:04:18 am by newbie_fpc »

korba812

  • Full Member
  • ***
  • Posts: 181
Are you using a shared connection? For example, the TIBConnection component is declared as a global variable and you use it between function calls?
Hard to guess without the code. Could you please show the code how you use these components in UDF library?

newbie_fpc

  • New member
  • *
  • Posts: 9
Here is the code. The defined IBExpoert UDF calls this function. I tried it as local and global variables, too.
Code: Pascal  [Select][+][-]
  1.   function getToken(params: PChar):PChar;stdcall; // cdecl
  2.   var
  3.     Client: TFPHttpClient;
  4.     Response : TStringList;
  5.     wwwParams, Token: string;
  6.     sClientId, sClientSecret, sRedirectURI, sAuthCode, sAccessToken, sRefreshToken, sTokenType: string;
  7.     iAuthPeriod, iGoogleapi_params_id: integer;
  8.  
  9.     jData, jData2 : TJSONData;
  10.     jObject, jObject2 : TJSONObject;
  11.  
  12.     conn: TSQLConnector;
  13.     query: TSQLQuery;
  14.  
  15.     hiba,jsonstring:string;
  16.   begin
  17.     try
  18.       begin
  19.         InitializeLogger();
  20.         logger.Info('getToken calling...');
  21.  
  22.         // input params
  23.         hiba:= '';
  24.         token:= '';
  25.         jsonstring := StrPas(params);
  26.         jData2 := GetJSON(jsonstring);
  27.         jObject2 := TJSONObject(jData2);
  28.         iGoogleapi_params_id := jObject2.Get('paramsID', 0);
  29.         hostname := jObject2.Get('hostname', '');
  30.         database := jObject2.Get('databasename', '');
  31.         user := jObject2.Get('user', '');
  32.         password := jObject2.Get('password', '');
  33.  
  34.         logger.Debug('Input params (database variable''s value): ' + database);
  35.  
  36.         database := ReplaceString(database,'\\','\');
  37.        
  38.         // database initialize
  39.         conn:=TSQLConnector.Create(nil);
  40.         conn.ConnectorType:='Firebird';
  41.         conn.HostName:=hostname;
  42.         conn.DatabaseName:=database;
  43.         conn.UserName:=user;
  44.         conn.Password:=password;
  45.         conn.LoginPrompt:=false;
  46.         conn.Transaction:=TSQLTransaction.Create(Conn);
  47.         //Conn.Transaction.Params.Add('isc_tpb_read_commited'); // WITH THESE THERE IS NO DIFFERENCE
  48.         //Conn.Transaction.Params.Add('isc_tpb_concurrency');
  49.         //Conn.Transaction.Params.Add('isc_tpb_nowait');
  50.         // https://wiki.freepascal.org/SqlDBHowto
  51.         conn.OnLog:= @loggerDB.LogDBEvents;
  52.         logger.Info('conn.OnLog @loggerDB.LogDBEvents');
  53.         conn.LogEvents:= LogAllEventsExtra; //= [detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack]
  54.         logger.Info('LogEvents enums set');
  55.         logger.Info('conn initialized...');
  56.  
  57.         query := TSQLQuery.Create(conn);
  58.         query.DataBase := conn;
  59.         logger.Info('TSQLQuery initialized...');
  60.  
  61.         // query the database
  62.         logger.Info('query database');
  63.         logger.Debug('Database exists: ' + BoolToStr(FileExists(conn.DatabaseName),'Y','N'));
  64.         logger.Debug('Database connected: ' + BoolToStr(conn.Connected = true,'Y,'N'));
  65.        logger.Debug('Database is not nil: ' + BoolToStr(conn <> nil,'Y','N'));
  66.        query.SQL.Text:= 'select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = :PARAMS_ID';
  67.        query.ParamByName('PARAMS_ID').AsInteger:= iGoogleapi_params_id;
  68.        //SQLTransaction1.active:= true; // setting Active to True will call StartTransaction, setting it to False will call TDBTransaction.EndTransaction
  69.        logger.Debug('before query.Open; , ' + query.SQL.Text);
  70.        logger.Debug('Database exists: ' + BoolToStr(FileExists(conn.DatabaseName),'I','N'));
  71.        logger.Debug('Database connected: ' + BoolToStr(conn.Connected = true,'I','N'));
  72.        logger.Debug('Database is not nil: ' + BoolToStr(conn <> nil,'I','N'));
  73.        if (FileExists(conn.DatabaseName)) then
  74.        begin
  75.          query.Open;
  76.          logger.Debug('after query.Open;');
  77.            sClientId := query.FieldByName('CLIENT_ID').AsString;
  78.            sClientSecret := query.FieldByName('CLIENT_SECRET').AsString;
  79.            sRedirectURI := query.FieldByName('REDIRECT_URI').AsString;
  80.            sAuthCode := query.FieldByName('AUTHCODE').AsString;
  81.          logger.Debug('query successfully executed: ' + sRedirectURI);
  82.          query.Close;
  83.          logger.Info('query GOOGLEAPI_PARAMS closed...');
  84.          //conn.Transaction.Commit; // = SQLTransaction1.active:= false;  // WITH THIS LINE THERE IS NO DIFFERENCE
  85.        end;
  86.        conn.close(); // = conn.Connected:=false;
  87.        logger.Debug('conn.close()');
  88.  
  89.        // POST request preparing
  90.        wwwParams := 'client_id='+trim(sClientId)
  91.                  +'&client_secret='+trim(sClientSecret)
  92.                  +'&grant_type='+'authorization_code'
  93.                  +'&redirect_uri='+ EncodeURLElement(trim(sRedirectURI))
  94.                  +'&code='+trim(sAuthCode);
  95.        Client := TFPHttpClient.Create(nil);
  96.        Client.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
  97.        Client.AddHeader('Content-Type','application/x-www-form-urlencoded');
  98.        Client.AddHeader('Accept', 'application/json');
  99.          //Client.AllowRedirect := true;
  100.          //Client.UserName:=USER;
  101.          //Client.Password:=PW;
  102.          //client.RequestBody := TRawByteStringStream.Create(Params);
  103.  
  104.        // a request response objektum initialize
  105.        Response := TStringList.Create;
  106.        logger.Debug('before client.FormPost token');
  107.        client.FormPost('https://accounts.google.com/o/oauth2/token',  wwwParams, Response);
  108.         Token := Response.Text;
  109.         // this is only a minimal sampling of what can be done with this API
  110.         // create from string
  111.         jData := GetJSON(Token);
  112.  
  113.         logger.Debug('jData := GetJSON(Token)');
  114.         logger.Debug('before Token.Contains(''access_token'')');
  115.         // if it does not contains ('access_token'), then something went wrong
  116.         if (Token.Contains('access_token')) then
  117.         begin
  118.           // output as a flat string
  119.           //s := jData.AsJSON;
  120.           // output as nicely formatted JSON
  121.           //s := jData.FormatJSON;
  122.           // cast as TJSONObject to make access easier
  123.           jObject := TJSONObject(jData);
  124.           // retrieve value of access_token
  125.           sAccessToken := jObject.Get('access_token', '');
  126.           sRefreshToken := jObject.Get('refresh_token', '');
  127.           sTokenType := jObject.Get('token_type', '');
  128.           iAuthPeriod := jObject.Get('expires_in', 0);
  129.           //sScope := jObject.Get('scope');
  130.  
  131.           query.close();
  132.           logger.Info('GOOGLEAPI_PARAMS table update token');
  133.           //conn.open();
  134.           //conn.StartTransaction;
  135.           query.SQL.Text:= 'update GOOGLEAPI_PARAMS set REFRESH_TOKEN=:REFRESH_TOKEN,ACCESS_TOKEN=:ACCESS_TOKEN,TOKEN_TYPE=:TOKEN_TYPE, ' +
  136.                'AUTH_EXPIRES=:AUTH_EXPIRES,AUTH_PERIOD=:AUTH_PERIOD ' +
  137.                'WHERE ID = :params_id';
  138.           query.ParamByName('params_id').AsInteger:= igoogleapi_params_id;
  139.           query.ParamByName('REFRESH_TOKEN').AsString:= sRefreshToken;
  140.           query.ParamByName('ACCESS_TOKEN').AsString:= sAccessToken;
  141.           query.ParamByName('TOKEN_TYPE').AsString:= sTokenType;
  142.           // AUTH_EXPIRES = Now+(AUTH_PERIOD-AuthExpiryMargin(=10, fpoauth2-ben látható))
  143.           query.ParamByName('AUTH_EXPIRES').AsDateTime:= Now()+(iAuthPeriod-10);
  144.           query.ParamByName('AUTH_PERIOD').AsInteger:= iAuthPeriod;
  145.           query.ExecSQL();
  146.           query.Close;
  147.           //SQLTransaction1.active:= false;
  148.           //conn.Transaction.Commit;
  149.           //conn.close();
  150.           //logger.Debug('conn.close()');
  151.         end;
  152.  
  153.       end
  154.     except
  155.       on E:EUpdateError do
  156.       begin
  157.         hiba := 'EUpdateError : ' + E.Context + ' - ' + E.Message;
  158.         logger.Error(hiba);
  159.       end;
  160.       on E:ESQLDatabaseError do
  161.       begin
  162.         hiba := 'ESQLDatabaseError : ' + E.SQLState + ' - ' + E.Message;
  163.         logger.Error(hiba);
  164.       end;
  165.       on E:EDatabaseError do
  166.       begin
  167.         hiba := 'EDatabaseError : ' + ' - ' + E.Message;
  168.         logger.Error(hiba);
  169.       end;
  170.       on E:Exception do
  171.       begin
  172.         hiba := 'Exception : ' + E.Message;
  173.         logger.Error(hiba);
  174.       end
  175.     end;
  176.  
  177.     try
  178.       begin
  179.         if ((hiba <> '') and (Token = '')) then
  180.           Result := PChar(hiba)//PAnsiChar(AnsiString(hiba))
  181.         else
  182.           Result := PChar(Token);//PAnsiChar(AnsiString(Token));
  183.         logger.Debug('Result: ' + StrPas(Result));
  184.  
  185.         if (Client <> nil) then
  186.         begin
  187.           FreeAndNil(Client);
  188.           logger.Info('FreeAndNil(Client);');
  189.         end;
  190.         if (Response <> nil) then
  191.         begin
  192.           FreeAndNil(Response);
  193.           logger.Info('FreeAndNil(Response);');
  194.         end;
  195.         if (jData <> nil) then
  196.         begin
  197.           FreeAndNil(jData);
  198.           logger.Info('FreeAndNil(jData);');
  199.         end;
  200.  
  201.         if (jData2 <> nil) then
  202.         begin
  203.           FreeAndNil(jData2);
  204.           logger.Info('FreeAndNil(jData2);');
  205.         end;
  206.         if (conn <> nil) then
  207.         begin
  208.           FreeAndNil(conn);
  209.           logger.Info('FreeAndNil(conn);');
  210.         end;
  211.         logger.Info('FreeAndNil ending');
  212.         FreeAndNil(loggerDB);
  213.         FreeAndNil(logger);
  214.       end
  215.     except
  216.       on E:EDatabaseError do
  217.       begin
  218.         hiba := 'EDatabaseError : ' + E.Message;
  219.         logger.Error(hiba);
  220.       end;
  221.       on E:EAccessViolation do
  222.       begin
  223.         hiba := 'EAccessViolation : ' + E.Message;
  224.         logger.Error(hiba);
  225.       end;
  226.       on E:exception do
  227.       begin
  228.         hiba := 'Something bad happened : ' + E.Message;
  229.         logger.Error(hiba);
  230.       end
  231.     end;
  232.   end;
  233.  
« Last Edit: June 09, 2021, 01:05:04 pm by newbie_fpc »

newbie_fpc

  • New member
  • *
  • Posts: 9
And this is the log's content:

Code: Text  [Select][+][-]
  1.  [2021-06-09 12:54:31.968 Info] Logger created
  2.  [2021-06-09 12:54:31.968 Info] loggerDB created
  3.  [2021-06-09 12:54:31.968 Debug] loggerDB.SetLogger(logger);
  4.  [2021-06-09 12:54:31.968 Info] getToken calling
  5.  [2021-06-09 12:54:31.968 Debug] Input params (database variable): D:\database.FDB
  6.  [2021-06-09 12:54:31.968 Info] conn.OnLog @loggerDB.LogDBEvents
  7.  [2021-06-09 12:54:31.968 Info] LogEvents enums set
  8.  [2021-06-09 12:54:31.968 Info] conn initialized
  9.  [2021-06-09 12:54:31.968 Info] TSQLQuery initialized
  10.  [2021-06-09 12:54:31.968 Info] query database
  11.  [2021-06-09 12:54:31.968 Debug] Database exists: I
  12.  [2021-06-09 12:54:31.968 Debug] Database connected: N
  13.  [2021-06-09 12:54:31.968 Debug] Database is not nil: I
  14.  [2021-06-09 12:54:31.968 Debug] before query.Open;, select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = :PARAMS_ID
  15.  
  16.  [2021-06-09 12:54:31.968 Debug] Database exists: I
  17.  [2021-06-09 12:54:31.968 Debug] Database connected: N
  18.  [2021-06-09 12:54:31.968 Debug] Database is not nil: I
  19.  [2021-06-09 12:54:31.983 Debug] Prepare:  TQuerySQLStatement : select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = :PARAMS_ID
  20.  [2021-06-09 12:54:31.983 Debug] ActualSQL: select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = ?
  21.  [2021-06-09 12:54:31.983 Debug] Prepare:  TQuerySQLStatement : select ind.rdb$index_name, ind.rdb$relation_name, ind.rdb$unique_flag, ind_seg.rdb$field_name, rel_con.rdb$constraint_type, ind.rdb$index_type from rdb$index_segments ind_seg, rdb$indices ind left outer join rdb$relation_constraints rel_con on rel_con.rdb$index_name = ind.rdb$index_name where (ind_seg.rdb$index_name = ind.rdb$index_name) and (ind.rdb$relation_name='GOOGLEAPI_PARAMS') order by ind.rdb$index_name;
  22.  [2021-06-09 12:54:31.983 Debug] Execute:  TQuerySQLStatement : select ind.rdb$index_name, ind.rdb$relation_name, ind.rdb$unique_flag, ind_seg.rdb$field_name, rel_con.rdb$constraint_type, ind.rdb$index_type from rdb$index_segments ind_seg, rdb$indices ind left outer join rdb$relation_constraints rel_con on rel_con.rdb$index_name = ind.rdb$index_name where (ind_seg.rdb$index_name = ind.rdb$index_name) and (ind.rdb$relation_name='GOOGLEAPI_PARAMS') order by ind.rdb$index_name;
  23.  [2021-06-09 12:54:31.983 Debug] Fetch:    select ind.rdb$index_name, ind.rdb$relation_name, ind.rdb$unique_flag, ind_seg.rdb$field_name, rel_con.rdb$constraint_type, ind.rdb$index_type from rdb$index_segments ind_seg, rdb$indices ind left outer join rdb$relation_constraints rel_con on rel_con.rdb$index_name = ind.rdb$index_name where (ind_seg.rdb$index_name = ind.rdb$index_name) and (ind.rdb$relation_name='GOOGLEAPI_PARAMS') order by ind.rdb$index_name;
  24.  [2021-06-09 12:54:31.983 Debug] Fetch:    select ind.rdb$index_name, ind.rdb$relation_name, ind.rdb$unique_flag, ind_seg.rdb$field_name, rel_con.rdb$constraint_type, ind.rdb$index_type from rdb$index_segments ind_seg, rdb$indices ind left outer join rdb$relation_constraints rel_con on rel_con.rdb$index_name = ind.rdb$index_name where (ind_seg.rdb$index_name = ind.rdb$index_name) and (ind.rdb$relation_name='GOOGLEAPI_PARAMS') order by ind.rdb$index_name;
  25.  [2021-06-09 12:54:31.983 Debug] Fetch:    select ind.rdb$index_name, ind.rdb$relation_name, ind.rdb$unique_flag, ind_seg.rdb$field_name, rel_con.rdb$constraint_type, ind.rdb$index_type from rdb$index_segments ind_seg, rdb$indices ind left outer join rdb$relation_constraints rel_con on rel_con.rdb$index_name = ind.rdb$index_name where (ind_seg.rdb$index_name = ind.rdb$index_name) and (ind.rdb$relation_name='GOOGLEAPI_PARAMS') order by ind.rdb$index_name;
  26.  [2021-06-09 12:54:31.983 Debug] Fetch:    select ind.rdb$index_name, ind.rdb$relation_name, ind.rdb$unique_flag, ind_seg.rdb$field_name, rel_con.rdb$constraint_type, ind.rdb$index_type from rdb$index_segments ind_seg, rdb$indices ind left outer join rdb$relation_constraints rel_con on rel_con.rdb$index_name = ind.rdb$index_name where (ind_seg.rdb$index_name = ind.rdb$index_name) and (ind.rdb$relation_name='GOOGLEAPI_PARAMS') order by ind.rdb$index_name;
  27.  [2021-06-09 12:54:31.983 Debug] Fetch:    select ind.rdb$index_name, ind.rdb$relation_name, ind.rdb$unique_flag, ind_seg.rdb$field_name, rel_con.rdb$constraint_type, ind.rdb$index_type from rdb$index_segments ind_seg, rdb$indices ind left outer join rdb$relation_constraints rel_con on rel_con.rdb$index_name = ind.rdb$index_name where (ind_seg.rdb$index_name = ind.rdb$index_name) and (ind.rdb$relation_name='GOOGLEAPI_PARAMS') order by ind.rdb$index_name;
  28.  [2021-06-09 12:54:31.983 Debug] Execute:  TQuerySQLStatement : select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = :PARAMS_ID
  29.  [2021-06-09 12:54:31.983 Debug] ParamValue: Parameter "PARAMS_ID" value : "1"
  30.  [2021-06-09 12:54:31.983 Debug] Fetch:    select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = :PARAMS_ID
  31.  [2021-06-09 12:54:31.983 Debug] Fetch:    select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = :PARAMS_ID
  32.  [2021-06-09 12:54:31.983 Debug] after query.Open;
  33.  [2021-06-09 12:54:31.983 Debug] query successfully executed: urn:ietf:wg:oauth:2.0:oob
  34.  [2021-06-09 12:54:31.983 Info] query GOOGLEAPI_PARAMS end
  35.  [2021-06-09 12:54:31.983 Debug] Rollback: Rolling back transaction
  36.  [2021-06-09 12:54:31.983 Debug] conn.close()
  37.  [2021-06-09 12:54:31.983 Debug] before client.FormPost token
  38.  [2021-06-09 12:54:32.390 Debug] jData := GetJSON(Token)
  39.  [2021-06-09 12:54:32.390 Debug] before Token.Contains('access_token')
  40.  [2021-06-09 12:54:32.390 Debug] Result: {
  41.   "error": "invalid_grant",
  42.   "error_description": "Bad Request"
  43. }
  44.  
  45.  [2021-06-09 12:54:32.390 Info] FreeAndNil(Client);
  46.  [2021-06-09 12:54:32.390 Info] FreeAndNil(Response);
  47.  [2021-06-09 12:54:32.390 Info] FreeAndNil(jData);
  48.  [2021-06-09 12:54:32.390 Info] FreeAndNil(jData2);
  49.  [2021-06-09 12:54:32.390 Info] FreeAndNil(conn);
  50.  [2021-06-09 12:54:32.390 Info] FreeAndNil ending
  51.  [2021-06-09 12:54:40.105 Info] Logger created
  52.  [2021-06-09 12:54:40.105 Info] loggerDB created
  53.  [2021-06-09 12:54:40.105 Debug] loggerDB.SetLogger(logger);
  54.  [2021-06-09 12:54:40.105 Info] getToken calling
  55.  [2021-06-09 12:54:40.105 Debug] Input params (database variable): D:\database.FDB
  56.  [2021-06-09 12:54:40.105 Info] conn.OnLog @loggerDB.LogDBEvents
  57.  [2021-06-09 12:54:40.105 Info] LogEvents enums set
  58.  [2021-06-09 12:54:40.105 Info] conn initialized
  59.  [2021-06-09 12:54:40.105 Info] TSQLQuery initialized
  60.  [2021-06-09 12:54:40.105 Info] query database
  61.  [2021-06-09 12:54:40.105 Debug] Database exists: I
  62.  [2021-06-09 12:54:40.105 Debug] Database connected: N
  63.  [2021-06-09 12:54:40.105 Debug] Database is not nil: I
  64.  [2021-06-09 12:54:40.105 Debug] before query.Open;, select CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, AUTHCODE from GOOGLEAPI_PARAMS WHERE ID = :PARAMS_ID
  65.  
  66.  [2021-06-09 12:54:40.105 Debug] Database exists: I
  67.  [2021-06-09 12:54:40.105 Debug] Database connected: N
  68.  [2021-06-09 12:54:40.105 Debug] Database is not nil: I
  69.  [2021-06-09 12:54:40.108 Error] ESQLDatabaseError : 08003 - TIBConnection : DoInternalConnect :
  70.  -connection shutdown
  71.  [2021-06-09 12:54:40.108 Debug] Result: ESQLDatabaseError : 08003 - TIBConnection : DoInternalConnect :
  72.  -connection shutdown
  73.  [2021-06-09 12:54:40.108 Error] EAccessViolation : Access violation
  74.  
« Last Edit: June 09, 2021, 01:06:29 pm by newbie_fpc »

korba812

  • Full Member
  • ***
  • Posts: 181
You seem to be using SQLDB correctly, but...

Code: Pascal  [Select][+][-]
  1. function getToken(params: PChar):PChar;stdcall; // cdecl
Should be 'cdecl'

Code: Pascal  [Select][+][-]
  1.         if ((hiba <> '') and (Token = '')) then
  2.           Result := PChar(hiba)//PAnsiChar(AnsiString(hiba))
  3.         else
  4.           Result := PChar(Token);//PAnsiChar(AnsiString(Token));
  5.  
In case you are returning cstring you must use the ib_util_malloc function to allocate the memory, otherwise the memory will not be properly disposed by the server and a memory leak will occur.
See: https://firebirdsql.org/en/writing-udfs-for-interbase/#writing_udfs_in_delphi_for_windows_platforms

I can see you are still using global variables (logger, loggerDB). Don't do this until you are sure they are thread-safe. See: https://www.ibexpert.net/ibe/pmwiki.php?n=Doc.CreatingUDFsInDelphi#IssuesToBe

newbie_fpc

  • New member
  • *
  • Posts: 9
I'm sorry for late reaction, i did not have time for this. Thanks for the tips, I'll try them today.

newbie_fpc

  • New member
  • *
  • Posts: 9
I tried those you suggested. I'm not using global varialbes now and tried ib_util_malloc function and cdecl convention, but the situation is the same. The procedure still gets "ESQLDatabaseError : 08003 - TIBConnection : DoInternalConnect : -connection shutdown" response from the 2nd run and so on.

There is something may help or useful info. Although I dont remember how it worked previously in IBExpert sql editor, but the "select udf_function(...) from rdb$database" works well, multiple times. There is no TIBConnection : DoInternalConnect : -connection shutdown.

korba812

  • Full Member
  • ***
  • Posts: 181
I looked again at the log you attached earlier and I didn't notice the last message:
Code: Pascal  [Select][+][-]
  1. [2021-06-09 12:54:40.108 Error] EAccessViolation : Access violation
  2.  
Maybe that's the reason. Try to find out what causes this exception.


Fantablup

  • Full Member
  • ***
  • Posts: 140
The exception:
ESQLDatabaseError : 08003 - TIBConnection : DoInternalConnect :
 -connection shutdown

I tried the IBConnection just for fun yesterday, and i got the same error.
I just tried it in the designer with setting active.
The first time i set active, it works.. Then i set active false, and again setting to active.
Now i get this error.
And none other components like Zeos DBconnection is working either after this.
I have to restart Lazarus for it to work again.

I guess it is something with the IBConnection.
« Last Edit: July 13, 2021, 08:58:23 pm by Fantablup »

 

TinyPortal © 2005-2018