Results 1 to 9 of 9

Thread: prepare insert statement

  1. #1
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382

    prepare insert statement

    (FireDAC) Na een Prepare() kan een insertstatement nog steeds ongeldig zijn. Bijvoorbeeld er staat een niet bestaand veld in de insert statement.
    Is het mogelijk de statement de valideren zonder echt uit te voeren?

  2. #2
    Hangt van je SQL-server af.

    In Microsoft SQL Server kun je dit opnemen boven je statement:
    SQL Code:
    1. SET PARSEONLY ON

    Voorbeeld met een TMSConnection. Moet je dus zelf even ombouwen en uittesten.
    Delphi Code:
    1. function IsSQLStatementSyntaxValid(con: TMSConnection; SQL: string): boolean;
    2. var
    3.   q: TMSQuery;
    4. begin
    5.   Result := False;
    6.   if (SQL = '') then exit;
    7.   q := nil;
    8.   try
    9.     q := TMSQuery.Create(nil);
    10.     q.Connection := con;
    11.     q.SQL.Text := 'SET PARSEONLY ON';
    12.     q.Execute;
    13.     try
    14.       try
    15.         q.SQL.Text := SQL;
    16.         q.Execute;
    17.         Result := True;
    18.       except
    19.       end;
    20.     finally
    21.       q.SQL.Text := 'SET PARSEONLY OFF';
    22.       q.Execute;
    23.     end;
    24.   finally
    25.     if Assigned(q) then
    26.       FreeAndNil(q);
    27.   end;
    28. end;
    29.  
    30. //...
    31. if IsSQLStatementSyntaxValid(MSConnection, 'Update Test Set a = 0 Where b in (Select id From Test WHERE id=:objid)') then
    32.   ShowMessage('Valid')
    33. else
    34.   ShowMessage('Not valid');
    (bron: http://forums.devart.com/viewtopic.php?t=19688)

  3. #3
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    ah... groots. Dank!
    Ga ik testen. ik was al iets bijijijna soortgelijks op het spoor.

  4. #4
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    voor sql server gebruik ik nu "set no exec on" (en daarna off natuurlijk)

  5. #5
    Weet jij wat het verschil is tussen SET PARSEONLY ON t.o.v. SET NOEXEC ON ?
    (Of wat het voordeel is van het een boven het abdere?)

  6. #6
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    nope... :-) Maar dat was degene die ik op het spoor was. Ik geloof dat noexec nieuwer is.
    Wel interessant...

  7. #7
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    van: https://social.msdn.microsoft.com/Fo...=sqlgetstarted

    PARSEONLY - Examines the syntax of each Transact-SQL statement and returns any error messages without compiling or executing the statement.

    NOEXEC - Compiles each query but does not execute it, ie, parsing a query and producing/adding the plan cache of the execution plan for the query, but not executing.

    In ieder geval klapte mijn insert sql in "noexec modus" op een ongeldig veld. En dat was precies wat ik nodig had.

  8. #8
    Quote Originally Posted by EricLang View Post
    In ieder geval klapte mijn insert sql in "noexec modus" op een ongeldig veld. En dat was precies wat ik nodig had.
    Ok, thanks, dat is dan duidelijk. PARSEONLY controleert alleen op syntax en niet op ongeldige veld en tabelnamen en NOEXEC compileert de statement maar voert deze niet uit en geeft wel melding op foute velden en tabellen.

  9. #9
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    hm... onze "no exec" werkt niet in alle omstandigheden geloof ik... onderzoek start weer :-(

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •