System.Data.SQLite
Check-in [7d432770a9]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove one set of surrounding single or double quotes from the data source value. This is needed because the connection string may have been built using the SQLiteConnectionStringBuilder class, which reuses connection string construction logic from inside the .NET Framwork itself. Fix for ticket [8c3bee31c8].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7d432770a95cee8372b884d601428174c71eaa6d
User & Date: mistachkin 2012-08-28 01:03:03
References
2012-08-28
01:03 Closed ticket [8c3bee31c8]: cannot open database file name containing spaces when built by SQLiteConnectionStringBuilder plus 4 other changes artifact: ab66c99584 user: mistachkin
Context
2012-08-28
02:31
Add links to the official NuGet packages to the download page. check-in: 9e12cdcbf9 user: mistachkin tags: trunk
01:03
Remove one set of surrounding single or double quotes from the data source value. This is needed because the connection string may have been built using the SQLiteConnectionStringBuilder class, which reuses connection string construction logic from inside the .NET Framwork itself. Fix for ticket [8c3bee31c8]. check-in: 7d432770a9 user: mistachkin tags: trunk
2012-08-24
10:09
Add doc comments for the ToFullPath connection string property. check-in: c9ec60e016 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteConnection.cs.

  1170   1170         bool fullUri = false;
  1171   1171         string fileName;
  1172   1172   
  1173   1173         if (Convert.ToInt32(FindKey(opts, "Version", DefaultVersion.ToString()), CultureInfo.InvariantCulture) != DefaultVersion)
  1174   1174           throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "Only SQLite Version {0} is supported at this time", DefaultVersion));
  1175   1175   
  1176   1176         fileName = FindKey(opts, "Data Source", DefaultDataSource);
         1177  +      fileName = UnwrapFileName(fileName);
  1177   1178   
  1178   1179         if (String.IsNullOrEmpty(fileName))
  1179   1180         {
  1180   1181           fileName = FindKey(opts, "Uri", DefaultUri);
  1181   1182           if (String.IsNullOrEmpty(fileName))
  1182   1183           {
  1183   1184             fileName = FindKey(opts, "FullUri", DefaultFullUri);
................................................................................
  1770   1771           {
  1771   1772               if (pArg != IntPtr.Zero)
  1772   1773                   Marshal.FreeHGlobal(pArg);
  1773   1774           }
  1774   1775   
  1775   1776           return rc;
  1776   1777       }
         1778  +
         1779  +    /// <summary>
         1780  +    /// Removes one set of surrounding single -OR- double quotes from the file
         1781  +    /// name and returns the resulting file name.  If the string is null, empty,
         1782  +    /// or contains quotes that are not balanced, nothing is done and the original
         1783  +    /// string will be returned.
         1784  +    /// </summary>
         1785  +    /// <param name="sourceFile">The database file name to process.</param>
         1786  +    /// <returns>The modified database file name.</returns>
         1787  +    private string UnwrapFileName(string sourceFile)
         1788  +    {
         1789  +        if (String.IsNullOrEmpty(sourceFile))
         1790  +        {
         1791  +            //
         1792  +            // NOTE: The string is null or empty, return it verbatim.
         1793  +            //
         1794  +            return sourceFile;
         1795  +        }
         1796  +
         1797  +        int length = sourceFile.Length;
         1798  +
         1799  +        if (((sourceFile[0] == '\'') && (sourceFile[length - 1] == '\'')) ||
         1800  +            ((sourceFile[0] == '"') && (sourceFile[length - 1] == '"')))
         1801  +        {
         1802  +            //
         1803  +            // NOTE: Remove the first and last character.
         1804  +            //
         1805  +            return sourceFile.Substring(1, length - 2);
         1806  +        }
         1807  +
         1808  +        //
         1809  +        // NOTE: No match, return the input string verbatim.
         1810  +        //
         1811  +        return sourceFile;
         1812  +    }
  1777   1813   
  1778   1814       /// <summary>
  1779   1815       /// Expand the filename of the data source, resolving the |DataDirectory|
  1780   1816       /// macro as appropriate.
  1781   1817       /// </summary>
  1782   1818       /// <param name="sourceFile">The database filename to expand</param>
  1783   1819       /// <param name="toFullPath">

Added Tests/tkt-8c3bee31c8.eagle.

            1  +###############################################################################
            2  +#
            3  +# tkt-8c3bee31c8.eagle --
            4  +#
            5  +# Written by Joe Mistachkin.
            6  +# Released to the public domain, use at your own risk!
            7  +#
            8  +###############################################################################
            9  +
           10  +package require Eagle
           11  +package require Eagle.Library
           12  +package require Eagle.Test
           13  +
           14  +runTestPrologue
           15  +
           16  +###############################################################################
           17  +
           18  +package require System.Data.SQLite.Test
           19  +runSQLiteTestPrologue
           20  +
           21  +###############################################################################
           22  +
           23  +runTest {test tkt-8c3bee31c8-1.1 {built connection string quoting} -setup {
           24  +  unset -nocomplain dataSource o result
           25  +} -body {
           26  +  set o [object create -alias System.Data.SQLite.SQLiteConnectionStringBuilder]
           27  +
           28  +  foreach dataSource [list \
           29  +        "C:\\test_path\\test.db" \
           30  +        "/test_path/test.db" \
           31  +        "C:\\test path\\test.db" \
           32  +        "/test path/test.db" \
           33  +        "C:\\test'path\\test.db" \
           34  +        "/test'path/test.db"] {
           35  +    $o DataSource $dataSource
           36  +    lappend result [list $dataSource [$o ToString]]
           37  +  }
           38  +
           39  +  set result
           40  +} -cleanup {
           41  +  unset -nocomplain dataSource o result
           42  +} -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
           43  +System.Data.SQLite} -result {{{C:\test_path\test.db}\
           44  +{data source=C:\test_path\test.db}} {/test_path/test.db\
           45  +{data source=/test_path/test.db}} {{C:\test path\test.db} {data source="C:\test\
           46  +path\test.db"}} {{/test path/test.db} {data source="/test path/test.db"}}\
           47  +{{C:\test'path\test.db} {data source="C:\test'path\test.db"}}\
           48  +{/test'path/test.db {data source="/test'path/test.db"}}}}
           49  +
           50  +###############################################################################
           51  +
           52  +runTest {test tkt-8c3bee31c8-1.2 {open single quoted file name} -setup {
           53  +  unset -nocomplain fileName o
           54  +} -body {
           55  +  set fileName [appendArgs ' [file join [getDatabaseDirectory] \
           56  +      tkt-8c3bee31c8-1.2.db] ']
           57  +
           58  +  set o [object create -alias System.Data.SQLite.SQLiteConnection]
           59  +  $o ConnectionString [appendArgs "Data Source=" $fileName \;]
           60  +  $o Open; # NOTE: This command may throw an exception, failing the test.
           61  +} -cleanup {
           62  +  unset -nocomplain fileName o
           63  +} -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
           64  +System.Data.SQLite} -result {}}
           65  +
           66  +###############################################################################
           67  +
           68  +runTest {test tkt-8c3bee31c8-1.3 {open double quoted file name} -setup {
           69  +  unset -nocomplain fileName o
           70  +} -body {
           71  +  set fileName [appendArgs \" [file join [getDatabaseDirectory] \
           72  +      tkt-8c3bee31c8-1.3.db] \"]
           73  +
           74  +  set o [object create -alias System.Data.SQLite.SQLiteConnection]
           75  +  $o ConnectionString [appendArgs "Data Source=" $fileName \;]
           76  +  $o Open; # NOTE: This command may throw an exception, failing the test.
           77  +} -cleanup {
           78  +  unset -nocomplain fileName o
           79  +} -constraints {eagle monoBug28 command.sql compile.DATA SQLite\
           80  +System.Data.SQLite} -result {}}
           81  +
           82  +###############################################################################
           83  +
           84  +runSQLiteTestEpilogue
           85  +runTestEpilogue