Jump to content

Mark Williams

Members
  • Content Count

    247
  • Joined

  • Last visited

Everything posted by Mark Williams

  1. Within an ISAPI dll I create a pooled connection: Params := TStringList.Create; try Params.Add('DriverID=PG'); Params.Add('User_Name=*****'); Params.Add('UnknownFormat=BYTEA'); Params.Add('Pooled=True'); FDManager := TFDManager.Create(Nil); with FDManager do begin ResourceOptions.SilentMode:=True; ResourceOptions.AutoReconnect:=True; AddConnectionDef(FD_POOLED_CONN, 'PG', Params); Active := true; end; finally Params.Free; end; The server is left as the default ie localhost. The server is a machine on my local network (ip 192.168.0.12). It is also a web server with an external id (say 52.132.222.67) It hosts a number of databases and to change the referenced database I call the following: var Def : IFDStanConnectionDef; begin try Def : =FDManager.ConnectionDefs.FindConnectionDef(FD_POOLED_CONN); if Def.Params.Values['Database'] <> dbName then Def.Params.Values['Database'] := dbName; if assigned(Query) then Query.Close; if assigned(Query) then Query.ConnectionName := FD_POOLED_CONN; except on E: Exception do AddToLog('Error SetDatabase: '+e.Message, leMajorError); end; If I call the dll via the external ip address then my function to change the referenced database works just fine. If I use local ip it fails with the following error: Why do I get this error if I use the local ip, but not if I call the dll with the external ip and is there any way around it?
  2. Mark Williams

    Problems changing database with pooled connection

    It has taken me an age to get back around to this, but I have finally uncovered the problem. It was not with FireDAC but my code.
  3. Using a Postgre database. If I run an insert query with the following code: # With FDQuery Do begin SQL.Text:='INSERT INTO temptab(email, name) ' +'VALUES (''email1'', ''name1''), ' +'(''email2'', ''name2'') ' +'returning id'; Open; end; The query returns two records containing the id for the newly inserted records. However, for larger inserts I want to use Array DML, but I also want to be get the returned data. Example code: With FDQuery Do begin SQL.Text:='INSERT INTO temptab(email, name) ' +'VALUES (:EMAIL, :NAME) returning id'; Params.BindMode:=pbByNumber; Params[0].DataType:=ftString; Params[0].DataType:=ftString; Params.ArraySize:=2; Params[0].AsStrings[0]:='Email1'; Params[1].AsStrings[0]:='Name1'; Params[0].AsStrings[1]:='Email2'; Params[1].AsStrings[1]:='Name2'; Execute(params.ArraySize); end; This returns no records. Not unsurprisingly as I am using the Execute command. If I change the Execute command to Open, it inserts just the first record from the array and returns the id for that new record. The Open function does not allow you to specify the ArraySize. I have tried to find some other procedure/property that will achieve this, but have drawn a blank. Does anyone know whether it is possible to return data from all inserted records using Array DML? If it is not possible can anyone suggest an efficient way for returning the inserted data? There seems to be two alternatives to me, neither of which is particularly attractive: Run a query to return all records that match the email and name and then extract the relevant ids. In large tables this would doubtless result in a significant overhead. Add an integer field to the table eg "temp_id". When inserting the data set this field to a unique value for all records inserted for the DML Array transaction and then retrieve the newly inserted data using "temp_id". Again, this doesn't appear to me to be an attractive solution. @Dmitry Arefiev If this is not currently possible with Array DML would you please consider including it for later versions?
  4. Mark Williams

    FireDAC Array DML returning values from inserted records

    Good to know thanks, but would be a bit of a major shift for me from FireDac to Zeos
  5. Mark Williams

    FireDAC Array DML returning values from inserted records

    Sorry, I though I had posted the SO link. It is FireDAC Array DML and Returning clauses - Stack Overflow
  6. Mark Williams

    FireDAC Array DML returning values from inserted records

    Sorry I misunderstood. What is SA?
  7. Mark Williams

    Embarcadero.com

    It seems to me that the Embarcadero web site(s) are a complete mess. I manage to find a resource one day and it's gone the next. As examples, I was advised to use https://idera.secure.force.com/CG/ to get to Quality Portal. I managed to get in to the Portal earlier this year and make a feature request, I returned to view it today and when I click on the Quality Portal link, it wants my username and password again, but not the same one. It wants the username and password for the Registered Product Page. Incidentally, this page also has a link for Registered Product, which takes a lifetime to load and is out of date! I use this link https://members.embarcadero.com/Login.aspx?returnurl=http%3a%2f%2fcc.embarcadero.com%2fmyreg to access Registered Product, which works. However, the username and password I use to access Registered Product does not work for Quality Portal because it won't accept an email as a username it wants your "real" username and I have no idea what that is. Tried a couple of options and none of them work. Is it just me or is this a complete mess? And is it beyond the wit of man to put links for all resources we need on one consistent web page with one username and password?
  8. Mark Williams

    Embarcadero.com

    Well I've not seen that site before today! Yes, it is annoying and pointless. I have made a note of the site for future reference. Of course, by the time I get around to looking at it, it will probably have moved somewhere else with n forwarding link.
  9. Mark Williams

    FireDAC Array DML returning values from inserted records

    http://FireDAC Array DML and Returning clauses - Stack Overflow
  10. Mark Williams

    Embarcadero.com

    I'll probably be dead by then!
  11. Mark Williams

    Embarcadero.com

    It's the same page as I get to via https://idera.secure.force.com/CG/. Still doesn't accept my credentials. But why all the different domains and different log ins required? It doesn't make any sense to me.
  12. Mark Williams

    FireDAC Array DML returning values from inserted records

    It's a bit frustrating and I have also posted on Stackoverflow, but nothing has come back. I have logged a feature request at Quality Portal. I would give you the link, but for some reason my log in details no longer work. If you could comment on that to lend support that would be great. That's assuming you know how to get in to it. I tried today, but my details no longer work!
  13. Mark Williams

    Email Tampering

    Apologies in advance as this isn't really an Indy question, but not sure where else to ask it. I have written functions to batch parse information from emails. I would also like to be able to flag up possible suspicious activity such as date tampering. One of the things I am looking at is the difference between the date time in the Date header and the date time of the first Received header. If there is a significant difference between the two then I will flag the item as suspicious. However, I am not sure what would be a significant time difference to warrant flagging. Anything more than a few minutes strikes me as too long and my initial view is to opt for about 30 minutes. Views as to whether that sounds sensible would be appreciated.
  14. Mark Williams

    Email Tampering

    It's not for filtering purposes. It is for a system that will store documents/resources including emails. When users are examining email threads I simply want to highlight that there may be something suspicious about one of the emails in the thread not exclude it from the thread. So if in 99% of the cases a Date header later than the Received header is suspicious that works for me. Perhaps my original question was unclear and answers have been given on the basis that I was looking to exclude such emails. Far from it, I am looking to highlight them. With that in mind perhaps I can ask my original question again. What sort of time difference by which the Date header is greater than the first Received header would you consider suspicious? I have opted for 30 minutes, but presumably there is an argument to say any difference is suspicious as I would expect most users' computers' and servers' clocks are automatically set.
  15. Mark Williams

    Email Tampering

    Thanks for the responses. Hadn't though of delayed sends. What I'm trying to catch is someone setting the date on their computer to a date in the past and sending an email to make it appear as though it was sent earlier than it in fact was. I haven't come across this, but surely if the Date header is later than the Received header someone's clock someone is showing the wrong time?
  16. Mark Williams

    FireDac PostgreSQL and TBatchMove

    Has anyone been able to get the BatchMove component to work correctly with PostgreSQL in AppendUpdate mode where there is an auto inc key field? My BatchMove component creation code is below. In addition, either the FDConnectionPG ExtendedMetaData param is set to true or the FDQueryPG updateOptions.AutoIncFields is set. Either way produces the same result, although I understand there is an efficiency hit with use of ExtendedMetaData. The problem is that whilst new rows get added to the table and my auto inc key field value gets set, it is running backwards ie -1, -2, -3 etc. Am I missing something or is this a bug? var FBatchMove: TFDBatchMove; FReader: TFDBatchMoveDataSetReader; FWriter: TFDBatchMoveSQLWriter; F:TField; begin FBatchMove := TFDBatchMove.Create(nil); FReader := TFDBatchMoveDataSetReader.Create(FBatchMove); FWriter := TFDBatchMoveSQLWriter.Create(FBatchMove); try FReader.DataSet:=FDQueryPG; FWriter.Connection:=FDConnectionPG; FWriter.TableName:='dummy'; FBatchMove.CommitCount:=1000; FBatchMove.Mode := dmAppendUpdate; FBatchMove.options:=FBatchmove.Options+[poIdentityInsert]; FBatchMove.Execute; finally FWriter.Free; FReader.Free; FBatchMove.Free; end;
  17. FireDAC Array DML doesn't seem to be usable in any practical sense with Returning clauses FireDAC Array DML returning values from inserted records. That being so, I am trying to work out whether there is an efficient way I can retrieve data from inserted records using Array DML. The following seems a possibility and is lightening fast, but I am concerned that I may be missing something critical: Insert required no of new records using Array DML within a StartTransaction/Commit section. Check the number of affected rows to make sure that all required records have been inserted. If not, then rollback. Obtain the last insert id for the target table for the current session. Work backwards through the array of inserted data in my app and assign the id by decrementing the last id. My initial testing suggests that this works. But it depends on the following assumptions being correct (which I believe they are): The RowsAffected property of TFDQuery is wholly reliable. My DB (in this case PostgreSQL) will always reliably return the correct last insert id for my table in my current session. My DB will insert all my records in the same order as they are added to the TFDQuery params list. My DB will insert the records in an unbroken sequence of IDs. So my questions Are my assumptions sound? Am I missing something else?
  18. Mark Williams

    Returning ids for records inserted with Array DML

    OK. I'm a little confused, but thanks for the help.
  19. Mark Williams

    Returning ids for records inserted with Array DML

    OK. As mentioned in original post if RowsAffected is less than the number of inserted rows I would expect I rollback the transaction (and handle it as an error). It is only if the RowsAffected = the number of inserted rows expected that I would use the approach in my original post. Taking that into account, do you think it is safe to do so?
  20. Mark Williams

    Returning ids for records inserted with Array DML

    But for an insert procedure would not the number of successful executions be the number of new rows inserted? That certainly seems to to be the case from the testing I have carried out so far.
  21. Mark Williams

    Returning ids for records inserted with Array DML

    Thanks for the suggestions. Just to clarify By that, do you mean that you consider the method I proposed in my original post would be reliable? If so, that would be the quickest and easiest route to go.
  22. Mark Williams

    IsElevated

    Is there a simple way to check if my app is running elevated? I can see a few oldish posts on this on Google, but nothing recent. I was just wondering if newer Delphi has introduced a simple function for it, although I couldn't find anything in help or likely units. Or perhaps there is a new Windows API procedure?
  23. Mark Williams

    IsElevated

    Thanks. I'll check it out
  24. Mark Williams

    isFileInUSe

    I have used the following function for checking if a file is in use for many years (it is recommended on numerous sites): function IsFileInUse(FileName: String): Boolean; var HFileRes: HFILE; hdl:THandle; begin Result := False; if not FileExists(FileName) then Exit; HFileRes := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); Result := (HFileRes = INVALID_HANDLE_VALUE); if not Result then CloseHandle(HFileRes); end; It still works fine for 32Bit, but not 64 bit. On 64 bit It always returns a valid handle even when the file is in use and thus reports that the file is not in use even when it is. Also, when run from the IDE in 64 bit it crashes with an EExternalException: "External exception C0000008" when trying to close the handle. I have found some posts on this via Google and it seems to be a known issue, the answer being to switch off some debug options. But I am not particularly troubled by the IDE bug. I am majorly concerned by the failure to detect that a file is in use! I've tried with CreateFileA and CreateFileW, but with the exactly the same result.
  25. Currently on 10.4, but have had this problem right back to 10.1. If I change a text property, caption, name, hint etc in the object inspector it does not stick when you click away on to some other IDE control such as say the form. You have to click on some other property in the object inspector and even then there is no guarantee that your change has been accepted. It's an absolute pain in the butt. Does anyone else have this issue and has anyone got any workarounds?
×