Forum > Databases

Access Violation on ExecSql (Sqlite3Connection)

(1/2) > >>

juancruz.ojeda:
Hi, I'm trying to insert some data into an Sqlite3 database and get an Access Violation when calling ExecSQL.

Here's my .dfm


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---object DataModule1: TDataModule1  OnCreate = DataModuleCreate  OldCreateOrder = False  Height = 294  HorizontalOffset = 1064  VerticalOffset = 480  Width = 420  PPI = 120  object SQLite3Connection1: TSQLite3Connection    Connected = False    LoginPrompt = False    DatabaseName = 'D:\InformeMedico\Archivos temporales\Maxity Proyect\DB\Maxity.db'    KeepConnection = False    Transaction = SQLTransaction1    AlwaysUseBigint = False    Left = 80    Top = 30  end  object SQLQuery1: TSQLQuery    IndexName = 'DEFAULT_ORDER'    MaxIndexesCount = 4    FieldDefs = <          item        Name = 'idarchivo'        DataType = ftInteger        Precision = -1      end          item        Name = 'nombrearchivo'        DataType = ftString        Precision = -1        Size = 50      end          item        Name = 'fechacreacion'        DataType = ftDateTime        Precision = -1      end          item        Name = 'ultimamodificacion'        DataType = ftDateTime        Precision = -1      end          item        Name = 'estado'        DataType = ftString        Precision = -1        Size = 35      end          item        Name = 'descripcion'        DataType = ftMemo        Precision = -1      end>    Database = SQLite3Connection1    Transaction = SQLTransaction1    SQL.Strings = (      'select * from archivos'    )    InsertSQL.Strings = (      ''    )    Params = <>    Macros = <>    Left = 256    Top = 30    object SQLQuery1idarchivo: TLongintField      FieldKind = fkData      FieldName = 'idarchivo'      Index = 0      LookupCache = False      ProviderFlags = [pfInUpdate, pfInWhere]      ReadOnly = False      Required = False    end    object SQLQuery1nombrearchivo: TStringField      FieldKind = fkData      FieldName = 'nombrearchivo'      Index = 1      LookupCache = False      ProviderFlags = [pfInUpdate, pfInWhere]      ReadOnly = False      Required = False      Size = 50    end    object SQLQuery1fechacreacion: TDateTimeField      FieldKind = fkData      FieldName = 'fechacreacion'      Index = 2      LookupCache = False      ProviderFlags = [pfInUpdate, pfInWhere]      ReadOnly = False      Required = False    end    object SQLQuery1ultimamodificacion: TDateTimeField      FieldKind = fkData      FieldName = 'ultimamodificacion'      Index = 3      LookupCache = False      ProviderFlags = [pfInUpdate, pfInWhere]      ReadOnly = False      Required = False    end    object SQLQuery1estado: TStringField      FieldKind = fkData      FieldName = 'estado'      Index = 4      LookupCache = False      ProviderFlags = [pfInUpdate, pfInWhere]      ReadOnly = False      Required = False      Size = 35    end    object SQLQuery1descripcion: TMemoField      FieldKind = fkData      FieldName = 'descripcion'      Index = 5      LookupCache = False      ProviderFlags = [pfInUpdate, pfInWhere]      ReadOnly = False      Required = False      BlobType = ftMemo      Transliterate = False    end  end  object SQLTransaction1: TSQLTransaction    Active = False    Database = SQLite3Connection1    Left = 119    Top = 125  endend 
Then on the DataModule1.Create I have this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDataModule1.DataModuleCreate(Sender: TObject);begin  SQLite3Connection1.Connected := True;end;  
And here's a method I implemented to to the Insert:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.InsertPath(APath: string);var  lSqlQuery: TSQLQuery;begin  lSqlQuery := TSQLQuery.Create(nil);  try    lSqlQuery.DataBase := DataModule1.SQLite3Connection1;    lSqlQuery.SQLTransaction := DataModule1.SQLTransaction1;    lSqlQuery.Sql.Text :=        'INSERT INTO Archivos (nombrearchivo, fechacreacion, estado) VALUES (:path, Now(), ''Registrado'')';    lSqlQuery.ParamByName('path').Text:='hola';    lSqlQuery.ExecSQL;  // <------ Here I get the access violation.    DataModule1.SQLTransaction1.Commit;    DataModule1.SQLQuery1.Active:= False;  finally    lSqlQuery.Free;  end;end;

The error message doesn't say too much:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---El proyecto monitoreo2 ha lanzado una excepci├│n 'External: ACCESS VIOLATION' con el mensaje:Access violation executing address $0000000000000000.
Any hint?

rvk:
Welcome to the forum.


--- Quote from: juancruz.ojeda on May 30, 2022, 03:21:55 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    lSqlQuery.ParamByName('path').Text:='hola';
--- End quote ---
Shouldn't that be

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---lSqlQuery.ParamByName('path').AsString := 'hola';

--- Quote from: juancruz.ojeda on May 30, 2022, 03:21:55 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    DataModule1.SQLQuery1.Active:= False;
--- End quote ---
You can remove that one.
Active := false or Close is only for when a query is opened.
ExecSQL just executes it and there isn't a returndataset to open or close.

Zvoni:
Are you sure, you're in the right forum?

--- Quote ---Here's my .dfm
--- End quote ---

btw: What's this supposed to do?

--- Quote ---'INSERT INTO Archivos (nombrearchivo, fechacreacion, estado) VALUES (:path, Now(), ''Registrado'')';
--- End quote ---
There is no "Now()"-Function in SQLite-SQL
It's either
"SELECT Date()" if you only need Date (Acc. to UTC!!!)
Or
"SELECT DateTime()" if you need Date with Time (acc. to UTC!!)
If you need localtime you have to use a localtime-modifier
see here: https://www.sqlite.org/lang_datefunc.html

Your INSERT would look like this (with localtime-modifier)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 'INSERT INTO Archivos (nombrearchivo, fechacreacion, estado) VALUES (:path, DateTime(''now'',''localtime''), ''Registrado'')';Or better: Use a Parameter for the DateTime

juancruz.ojeda:
Thank you, replacing "now()" for DateTime() appears to work okay.
What generated confusion was mainly the "access violation" message instead of a SQLite error message.

Zvoni:

--- Quote from: juancruz.ojeda on May 30, 2022, 06:30:22 pm ---Thank you, replacing "now()" for DateTime() appears to work okay.
What generated confusion was mainly the "access violation" message instead of a SQLite error message.

--- End quote ---
Remember: DateTime() without any modifier returns UTC!!

Navigation

[0] Message Index

[#] Next page

Go to full version