Author Topic: unable to delete files with ' char in their names  (Read 4316 times)

xkrystof

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
unable to delete files with ' char in their names
« on: September 17, 2008, 06:30:22 pm »
Hi,
have You ever met problems, when deleting use-case files via Api?
I can not delete files:
usecaseElement.GetFiles().Delete(...)

which have apostroph sign ' inside their paths...
\Use-Case\User's Environment Management\x.doc

- Even I can not rename them (the method SetName(...)) - consequent Update() returns false and GetLastError or similar methods return
Syntax error (missing operator) in query expression 'Object_ID=6606 AND Filename='Use-Case\User's Environment Management\x.doc'.
DAO.QueryDef [3075]


as a result, the exception is thrown
java.lang.Exception: I
      at org.sparx.Collection.comDelete(Native Method)
      at org.sparx.Collection.Delete(Collection.java:108)


Appearently, there are to many apostroph characters in the result ...

Is this bug?
« Last Edit: September 17, 2008, 09:36:57 pm by xkrystof »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #1 on: September 18, 2008, 01:34:25 am »
No, it is an error in your code.

Most databases will react badly if you have enclosed a quote mark (single or double) inside a quoted string that is delimited with the same quote mark.

Your code is essentially saying to the database: "...like 'Use-Case\User'" followed by "s Environment..." As you can see, what's after the second apostrophe is being interpreted as (poorly formed) SQL, causing the syntax error.

Depending on the language you are using, you need to escape the apostrophes in the input string. Many languages, and most SQL interpreters, do this by using a double apostrophe.

HTH, David
No, you can't have it!

mrf

  • EA User
  • **
  • Posts: 311
  • Karma: +0/-0
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #2 on: September 18, 2008, 08:49:15 am »
It might be worth pointing out at this stage that the truncation of Java exception messages has been addressed, the fix _should_ appear in the next version of EA.

Hopefully that means in situations like these, users will have a lot more information at their disposal to address these problems.
Best Regards,

Michael

[email protected]
"It is more complicated than you think." - RFC 1925, Section 2.8

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #3 on: September 18, 2008, 09:21:36 pm »
Which still leaves us with the question: did escaping the embedded apostrophe solve the problem? If so, then between that step and the error message improvement, we've nailed this.
No, you can't have it!

lubos

  • EA User
  • **
  • Posts: 101
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #4 on: September 19, 2008, 04:52:18 am »
xkrystof is right, there is problem with EA.
If you already HAVE some element with the atached file  containing apostrofe in it's name. (This element was created "by hand"  using EA.)
You can't change the file name by program through API, since EA creates SQL command with WHERE part like >>>Object_ID=6606 AND Filename='OLD file name with 'apostrofe.doc' <<<
So you are not able to change the already existing file name.

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #5 on: September 19, 2008, 06:30:08 am »
You can probably work around this by formatting a string which will result in a valid WHERE clause. But of course this should not be up to us users of the api, but EA automation should take any old filename and take care of all formatting problems. When we have an interface like DeleteFile(string), how are we to know which characters we have to mask?

For users of the api it should not matter at all whether the implementation uses sql, or xml, or witchcraft. When you need to know implementation details to use the api it's bad api.

 And if you can create a file but not change it's name then it's inconsistent api. Paolo, where are you?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #6 on: September 19, 2008, 10:59:43 am »
One of you with an example project should submit a bug report. Use the Registered Users version of the report, since you can attach a (compressed) example project. This will help Sparx deal with the issue.
No, you can't have it!

xkrystof

  • EA User
  • **
  • Posts: 29
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #7 on: September 19, 2008, 05:42:20 pm »
Thank  You for all comments ...
I will submit this as a bug.


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: unable to delete files with ' char in their na
« Reply #8 on: September 19, 2008, 08:58:54 pm »
Thanks much.

Please keep us posted [no pun intended, really] on what Sparx has to say about this.
No, you can't have it!