Skip to main content
June 15, 2012
Question

SQLConnection.attach() fails when file path contains apostrophe

  • June 15, 2012
  • 6 replies
  • 1671 views

Hello,

Any help on this would be much appreciated. Issue occurs when user has apostrophe in their windows username and therefore an apostrophe in their File.applicationStorageDirectory path.

e.g. if the user logs into windows as j.o'reilly, then it will be:

C:\Documents and Settings\j.o'reilly\Application Data\application name\local store

Have tried with Air Runtimes: 2.5.0.16600,2.6.0.19120,3.2.2070

Have tried with Air SDKs: 2.0, 2.7, 4.5

To replicate without creating a windows user with an apostrophe, the same result occurs if the files themselves are named with an apostrophe:

var __connection:SQLConnection;

__connection = new SQLConnection();

__connection.open( File.applicationStorageDirectory.resolvePath("mainfile.s3db"), SQLMode.UPDATE );

__connection.attach( "secondary", File.applicationStorageDirectory.resolvePath("user'name.s3db") );


Result:

SQLError: 'Error #3125: Unable to open the database file.', details:'near 'name': syntax error', operation:'attach', detailID:'2003'

    at flash.data::SQLConnection/internalAttach()

This topic has been closed for replies.

6 replies

Carl_Sun
Participant
July 25, 2012

You can try another easier workaround:

var file:File = File.applicationDirectory.resolvePath("Fred's\\neat.db");

var escapedFile:File = new File();

var singleQuoteMatchPattern:RegExp = /'/g;

escapedFile.nativePath = file.nativePath.replace(singleQuoteMatchPattern:RegExp, "''");

sqlConnection.attach("test", escapedFile);

Carl_Sun
Participant
July 24, 2012

A workaround is to create a hard link for the database file, and attach the hard link instead.

The hard link can be created by either command "mklink /h ..." or Windows API function "CreateHardLink". The mklink command seems available only on Vista or later, while the "CreateHardLink" works on XP or later.

chris.campbell
Legend
June 20, 2012

Could you please open a new bug report on this over at bugbase.adobe.com?  Please post back with the URL so that others affected can add their comments and votes.

Given that this has been around so long, we'll need strong community support for this issue to have a good chance at it being fixed.  Is there any ways you can work around this in the meantime?  Can the apostrophe be escaped?

June 21, 2012

https://bugbase.adobe.com/index.cfm?event=bug&id=3220380

Community support? You mean I can checkout the source of flash.data.SQLConnection and fix it? Can you please post the repo url?

The workarounds we attempted involved escaping the apostrophe were defeated by the File class removing the escaping.

//Attach() Does not accept strings

File.applicationStorageDirectory.resolvePath(sqliteFileVO.fileName).nativePath

//Attach will not work with files which have their path escaped DOS style

var f:File = new File( '"' + File.applicationStorageDirectory.resolvePath(sqliteFileVO.fileName).nativePath + '"');

//Passing as url does not escape the apostrophe

var f:File = new File(File.applicationStorageDirectory.resolvePath(sqliteFileVO.fileName).url);

//passing using url notation does not escape the apostrophe

var f:File = new File("app-storage:/"+sqliteFileVO.fileName);

//Escaping the native path this way means the file cannot be found

f.nativePath = f.nativePath.replace(r,"%27");

//Escaping the native path this way does not work

f.nativePath = '"'+f.nativePath+'"';

//cannot be escaped with \ or / they will be interpreted as separator

//you may pass in escaped file path, but File will unescape it for us immediately

var regfind:RegExp = /'/g; //'

var strreplace:String = "%27";                   

var strclean:String = fileName.replace(regfind,strreplace);

file = new File("app-storage:/"+strclean);