Forum > Databases

[SOLVED] SQLite record exists

(1/5) > >>

Pe3s:
Hello, how to check if a record exists?

dseligo:

--- Quote from: Pe3s on November 30, 2022, 11:21:00 am ---Hello, how to check if a record exists?

--- End quote ---

If I didn't misunderstood you:

--- 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";}};} ---SQL.Text := 'select ... from ... where ...';  Open;  If not Eof then // this is check if you get anything

Чебурашка:
This works also with other DBMS, not only with SQLite.


--- 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";}};} ---var  query:TSQLQuery;begin  [...]  query.SQL.Text := 'select count(*) as cnt from Table where (recordKey = :recordKey)'; // table name and condition will depend on your structure  query.ParamByName('recordKey').AsInteger := 45; // params and related types will depend on your structure  [...]    query.Open();  exists := (query.FieldByName('cnt').AsInteger > 0); // if recordKey is primary key, and record exists this will be 1, otherwise 0, if recordKey is just a matching condition, count can be more than 1 if it maches  query.Close(); 

Zvoni:

--- Quote from: Pe3s on November 30, 2022, 11:21:00 am ---Hello, how to check if a record exists?

--- End quote ---
Whatever for would you need that?

Handoko:
tt's suggestion should work. I did it on Firebird, that was very similar to the code on the reply #2.

Navigation

[0] Message Index

[#] Next page

Go to full version