<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[My Visual Database — avoid the same input if it exist in table ?]]></title>
		<link>https://myvisualdatabase.com/forum/viewtopic.php?id=588</link>
		<atom:link href="https://myvisualdatabase.com/forum/extern.php?action=feed&amp;tid=588&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in avoid the same input if it exist in table ?.]]></description>
		<lastBuildDate>Tue, 21 Nov 2023 00:22:45 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49764#p49764</link>
			<description><![CDATA[<p>Hi T,<br />I guess we all have our own slightly different ways of testing for duplicates.<br />Attached is another option (as always, I like to keep things simple and my script as small as possible).<br />Its down-side (albeit not a major one) is that it introduces an element of data redundancy by storing a concatenation of the particular fields that you want to perform a duplicate check against.<br />Anyway, maybe it can give you some ideas.<br />Regards,<br />Derek.</p>]]></description>
			<author><![CDATA[null@example.com (derek)]]></author>
			<pubDate>Tue, 21 Nov 2023 00:22:45 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49764#p49764</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49762#p49762</link>
			<description><![CDATA[<p>So... I have been struggling quite a bit with the duplicate checking on records already existing when updating and I finally found something that works.</p><p>The above works well for a new record but it blocks any update on existing records considering an edit as a systemic duplicate.</p><p>My form has a double function of inserting new entries and displaying existing records so, the &quot;show record&quot; and &quot;new record&quot; do not behave as expected, especially the &quot;show record&quot; that requires to double-clic twice (4 clicks) to retrieve the current id/generated id. </p><p>If someone has the same kind of issue, here is the fruition of a long battle and some headaches.</p><p>The key is in the operator != which compares the values left and right and returns a false instead of the &lt;&gt; which returns a true and with SQL all conditions must be true to get a true result. If at least one condition is false then the result could be either false or incomplete, This is why it did not worked for updates since the result was always true, hence duplicate alert. In a new record, the ids old (-1) and new (next id number) are different while when updating, the ids are the same. SQLite creates internally an &quot;old.id&quot; and a &quot;new.id&quot; before each transaction, those can also be used in triggers and are used for internal rollback.</p><div class="codebox"><pre><code>procedure Form_SaveButtonName_OnClick (Sender: string; var Cancel: boolean);
var id: integer;
begin

  if  (SQLExecute (&#039;SELECT COUNT(id) FROM table WHERE (column COLLATE NOCASE =&quot;&#039;+Form.TextBox.Text+&#039;&quot;) and (id!=&quot;&#039;+inttostr(Form.SaveButtonName.dbGeneralTableId)+&#039;&quot;)&#039;)) &gt; 0 then
     begin  // Replace &lt;Record&gt; by proper descriptive field
          MessageDlg(&#039;This &lt;Record&gt; already exists:  &#039; +Form.TextBox.Text +#13+&#039;Entry canceled&#039;, mtError, mbOk, 0); // Displays a red &#039;X&#039;, header is: Error
          Cancel := True;
          end
          else
          begin
           MessageDlg(&#039;This &lt;Record&gt; has been saved:  &#039; +Administration.Administr_WinID.Text, mtInformation, mbOk, 0); // Displays an Info icon header is: Information
          Cancel := False;
     end;

end;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Mon, 20 Nov 2023 20:56:52 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49762#p49762</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49689#p49689</link>
			<description><![CDATA[<div class="quotebox"><cite>tcoton wrote:</cite><blockquote><p>That is what the collate nocase does! <img src="https://myvisualdatabase.com/forum/img/smilies/wink.png" width="15" height="15" alt="wink" /></p></blockquote></div><p>Search through LIKE in the program is case-insensitive. <br />And searching without &quot;%&quot; at the end and at the beginning will allow you to search for a complete match.<br />For spaces at the end and beginning of text, use TRIM. It’s better if it’s still at the stage of entering into EDIT. <br />Unfortunately, nothing will protect against extra spaces inside the text, commas, periods, apostrophes, etc. <br />Of course, all this can be processed.<br />As for COLLATE, there are some restrictions that do not always allow its use. And you only forcefully turn it on.<br />There are other options for limiting duplicate entries.</p>]]></description>
			<author><![CDATA[null@example.com (sparrow)]]></author>
			<pubDate>Sat, 11 Nov 2023 15:44:35 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49689#p49689</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49687#p49687</link>
			<description><![CDATA[<p>That is what the collate nocase does! <img src="https://myvisualdatabase.com/forum/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Sat, 11 Nov 2023 14:43:56 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49687#p49687</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49685#p49685</link>
			<description><![CDATA[<div class="quotebox"><cite>tcoton wrote:</cite><blockquote><p>It worked the other way around, I tested it but you are right, it looks more logical your way. </p><p>Now, I have to find a way to check on the vicious duplicates, the one mixing lower case and uppercase like: HR ..... Hr ..... hr ....&nbsp; hR ...., Human Resources..... human resources&nbsp; .... HUMAN RESOURCES ....&nbsp; those are all duplicates!!! <img src="https://myvisualdatabase.com/forum/img/smilies/sad.png" width="15" height="15" alt="sad" /></p></blockquote></div><div class="codebox"><pre><code>procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
  if DupliChk(Form1.Edit1.dbTable,Form1.Edit1.dbField,Form1.Edit1.Text) then
  begin   //replace object by self-explanatory text
    MessageDlg(&#039;This object already exists:  &#039; +Form1.Edit1.Text +#13+&#039;Entry cancelled&#039;, mtError, mbOk, 0); // Displays a red &#039;X&#039;, header is: Error
    Cancel := True;
    Form1.Edit1.Clear;
  end;
end;

function DupliChk (sTable, sField, sValue: string;): boolean;
begin
  if (SQLExecute (&#039;SELECT Count(*) FROM &#039;+sTable+&#039; WHERE upper(&#039;+sField+&#039;) = upper(&quot;&#039; + sValue + &#039;&quot;)&#039;) = 0) then
      result := False else result := True;
end;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (pavlenko.vladimir.v)]]></author>
			<pubDate>Sat, 11 Nov 2023 14:27:12 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49685#p49685</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49674#p49674</link>
			<description><![CDATA[<p>Got it, to check case insensitive duplicates, use COLLATE NOCASE:</p><div class="codebox"><pre><code>function DupliChk (sTable, sField, sValue: string;): boolean;
var d: string;
begin

    d := SQLExecute (&#039;SELECT Count(*) FROM &#039;+sTable+&#039; WHERE &#039;+sField+&#039; COLLATE NOCASE = &quot;&#039; + sValue + &#039;&quot;&#039;);
    if StrToInt(d) &gt; 0 then result := True else result := False;
end;</code></pre></div><p>It works until someone tries to cheat it with a space before or after the entry...</p>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Fri, 10 Nov 2023 20:42:38 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49674#p49674</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49673#p49673</link>
			<description><![CDATA[<p>It worked the other way around, I tested it but you are right, it looks more logical your way. </p><p>Now, I have to find a way to check on the vicious duplicates, the one mixing lower case and uppercase like: HR ..... Hr ..... hr ....&nbsp; hR ...., Human Resources..... human resources&nbsp; .... HUMAN RESOURCES ....&nbsp; those are all duplicates!!! <img src="https://myvisualdatabase.com/forum/img/smilies/sad.png" width="15" height="15" alt="sad" /></p>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Fri, 10 Nov 2023 20:04:39 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49673#p49673</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49668#p49668</link>
			<description><![CDATA[<div class="quotebox"><cite>tcoton wrote:</cite><blockquote><p>I transformed your solution into a function as it is easier when used repeatedly. It works perfectly when using a form that was not called by a &quot;New Record&quot; button.</p></blockquote></div><div class="codebox"><pre><code>function DupliChk (sTable, sField, sValue: string;): boolean;
var d: string;
begin
    result := False;
    d := SQLExecute (&#039;SELECT Count(*) FROM &#039;+sTable+&#039; WHERE &#039;+sField+&#039; = &quot;&#039; + sValue + &#039;&quot;&#039;);
    if StrToInt(d) &gt; 0 then result := True;
end;</code></pre></div><p>If I understand correctly, then you instantly changed the answer (False)<br />&nbsp; <br />Do it in this way<br /></p><div class="codebox"><pre><code>function DupliChk (sTable, sField, sValue: string;): boolean;
var d: string;
begin
    d := SQLExecute (&#039;SELECT Count(*) FROM &#039;+sTable+&#039; WHERE &#039;+sField+&#039; = &quot;&#039; + sValue + &#039;&quot;&#039;);
    if StrToInt(d) &gt; 0 then result := True else result := False;
end;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (pavlenko.vladimir.v)]]></author>
			<pubDate>Fri, 10 Nov 2023 15:17:16 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49668#p49668</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49667#p49667</link>
			<description><![CDATA[<p>I transformed your solution into a function as it is easier when used repeatedly. It works perfectly when using a form that was not called by a &quot;New Record&quot; button.</p><div class="codebox"><pre><code>function DupliChk (sTable, sField, sValue: string;): boolean;
var d: string;
begin
    result := False;
    d := SQLExecute (&#039;SELECT Count(*) FROM &#039;+sTable+&#039; WHERE &#039;+sField+&#039; = &quot;&#039; + sValue + &#039;&quot;&#039;);
    if StrToInt(d) &gt; 0 then result := True;
end;</code></pre></div><br /><p>And the usage is:</p><div class="codebox"><pre><code>procedure Form_ButtonSave_OnClick (Sender: string; var Cancel: boolean);
begin

   if DupliChk(&#039;Table&#039;,&#039;Column&#039;,Form.EditBox.Text) then
     begin   //replace object by self-explanatory text
          MessageDlg(&#039;This object already exists:  &#039; +Form.EditBox.Text +#13+&#039;Entry cancelled&#039;, mtError, mbOk, 0); // Displays a red &#039;X&#039;, header is: Error
          Cancel := True;
          Form.EditBox.Clear;  
     end;
end;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Fri, 10 Nov 2023 14:59:12 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49667#p49667</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49649#p49649</link>
			<description><![CDATA[<p>Thanks pavlenko.vladimir.v, that looks so simple, I feel dumb.</p>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Thu, 09 Nov 2023 16:33:56 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49649#p49649</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49648#p49648</link>
			<description><![CDATA[<div class="quotebox"><cite>tcoton wrote:</cite><blockquote><p>It actually does not work with the action &#039;SaveRecord&#039;. I have attached an example of what I am trying to achieve.</p><p>I want a very simple way of checking duplicates in a handful of tables in the same way as the example.</p></blockquote></div><div class="codebox"><pre><code>procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
  if (SQLExecute (&#039;SELECT COUNT(id) FROM HardWDType WHERE Kind=&quot;&#039;+Form1.Edit1.Text+&#039;&quot;&#039;) &gt; 0) then
  begin
    MessageDlg(&#039;This Kind is already in use: &#039; +Form1.Edit1.Text, mtError, mbOk, 0); // Displays a red &#039;X&#039;, header is: Error
    Cancel := True;
  end;
end;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (pavlenko.vladimir.v)]]></author>
			<pubDate>Thu, 09 Nov 2023 16:01:34 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49648#p49648</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49647#p49647</link>
			<description><![CDATA[<p>It actually does not work with the action &#039;SaveRecord&#039;. I have attached an example of what I am trying to achieve.</p><p>I want a very simple way of checking duplicates in a handful of tables in the same way as the example.</p>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Thu, 09 Nov 2023 15:40:28 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49647#p49647</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49641#p49641</link>
			<description><![CDATA[<div class="quotebox"><cite>tcoton wrote:</cite><blockquote><p>I am using Dmitry example up in the post.</p></blockquote></div><p>Action=&#039;SaveRecord&#039;&nbsp; -&nbsp; occurs when saving</p>]]></description>
			<author><![CDATA[null@example.com (pavlenko.vladimir.v)]]></author>
			<pubDate>Thu, 09 Nov 2023 05:23:31 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49641#p49641</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49637#p49637</link>
			<description><![CDATA[<div class="quotebox"><cite>pavlenko.vladimir.v wrote:</cite><blockquote><div class="quotebox"><cite>tcoton wrote:</cite><blockquote><p>This method works only when using a &quot;New Record&quot; button, it does not work with a &quot;Save Record&quot; button.</p><p>I tried to add the Action=&#039;SaveRecord&#039; but it might be another string sent when using a &quot;Save Record&quot; button:</p><div class="codebox"><pre><code>..[snip]....if (Action = &#039;NewRecord&#039;) or (Action=&#039;SaveRecord&#039;) then....[snip]....</code></pre></div><p>Does anyone knows what the string sent is?</p></blockquote></div><p>?????</p></blockquote></div><p>I am using Dmitry example up in the post.</p>]]></description>
			<author><![CDATA[null@example.com (tcoton)]]></author>
			<pubDate>Wed, 08 Nov 2023 23:04:54 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49637#p49637</guid>
		</item>
		<item>
			<title><![CDATA[Re: avoid the same input if it exist in table ?]]></title>
			<link>https://myvisualdatabase.com/forum/viewtopic.php?pid=49636#p49636</link>
			<description><![CDATA[<div class="quotebox"><cite>tcoton wrote:</cite><blockquote><p>This method works only when using a &quot;New Record&quot; button, it does not work with a &quot;Save Record&quot; button.</p><p>I tried to add the Action=&#039;SaveRecord&#039; but it might be another string sent when using a &quot;Save Record&quot; button:</p><div class="codebox"><pre><code>..[snip]....if (Action = &#039;NewRecord&#039;) or (Action=&#039;SaveRecord&#039;) then....[snip]....</code></pre></div><p>Does anyone knows what the string sent is?</p></blockquote></div><p>?????</p>]]></description>
			<author><![CDATA[null@example.com (pavlenko.vladimir.v)]]></author>
			<pubDate>Wed, 08 Nov 2023 22:49:30 +0000</pubDate>
			<guid>https://myvisualdatabase.com/forum/viewtopic.php?pid=49636#p49636</guid>
		</item>
	</channel>
</rss>
