System.Data.SQLite

Check-in [71cc174339]
Login

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

Overview
Comment:Add FileName property to the SQLiteConnection class.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | dbFileName
Files: files | file ages | folders
SHA1: 71cc174339f8fa69f27bebba3be654f8822b035f
User & Date: mistachkin 2015-09-04 19:59:36.639
Context
2015-09-04
22:41
Refactor how the DataDirectory 'macro' is handled. Closed-Leaf check-in: f6b0cf9152 user: mistachkin tags: dbFileName
19:59
Add FileName property to the SQLiteConnection class. check-in: 71cc174339 user: mistachkin tags: dbFileName
2015-08-25
21:16
Remove duplicate (and incorrect for Visual Studio 2015) link from the download page. check-in: 463bcfb351 user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLite3.cs.
852
853
854
855
856
857
858




































859
860
861
862
863
864
865
    /// <returns>
    /// Non-zero if the associated native connection handle is open.
    /// </returns>
    internal override bool IsOpen()
    {
        return (_sql != null) && !_sql.IsInvalid && !_sql.IsClosed;
    }





































    internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
    {
      //
      // NOTE: If the database connection is currently open, attempt to
      //       close it now.  This must be done because the file name or
      //       other parameters that may impact the underlying database







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
    /// <returns>
    /// Non-zero if the associated native connection handle is open.
    /// </returns>
    internal override bool IsOpen()
    {
        return (_sql != null) && !_sql.IsInvalid && !_sql.IsClosed;
    }

    /// <summary>
    /// Returns the fully qualified path and file name for the currently open
    /// database, if any.
    /// </summary>
    /// <param name="dbName">
    /// The name of the attached database to query.
    /// </param>
    /// <returns>
    /// The fully qualified path and file name for the currently open database,
    /// if any.
    /// </returns>
    internal override string GetFileName(string dbName)
    {
        if (_sql == null)
            return null;

        IntPtr pDbName = IntPtr.Zero;

        try
        {
            pDbName = (dbName != null) ?
                SQLiteString.Utf8IntPtrFromString(dbName) : IntPtr.Zero;

            return UTF8ToString(UnsafeNativeMethods.sqlite3_db_filename(
                _sql, pDbName), -1);
        }
        finally
        {
            if (pDbName != IntPtr.Zero)
            {
                SQLiteMemory.Free(pDbName);
                pDbName = IntPtr.Zero;
            }
        }
    }

    internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
    {
      //
      // NOTE: If the database connection is currently open, attempt to
      //       close it now.  This must be done because the file name or
      //       other parameters that may impact the underlying database
Changes to System.Data.SQLite/SQLiteBase.cs.
88
89
90
91
92
93
94












95
96
97
98
99
100
101
    /// <summary>
    /// Determines if the associated native connection handle is open.
    /// </summary>
    /// <returns>
    /// Non-zero if a database connection is open.
    /// </returns>
    internal abstract bool IsOpen();












    /// <summary>
    /// Opens a database.
    /// </summary>
    /// <remarks>
    /// Implementers should call SQLiteFunction.BindFunctions() and save the array after opening a connection
    /// to bind all attributed user-defined functions and collating sequences to the new connection.
    /// </remarks>







>
>
>
>
>
>
>
>
>
>
>
>







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    /// <summary>
    /// Determines if the associated native connection handle is open.
    /// </summary>
    /// <returns>
    /// Non-zero if a database connection is open.
    /// </returns>
    internal abstract bool IsOpen();
    /// <summary>
    /// Returns the fully qualified path and file name for the currently open
    /// database, if any.
    /// </summary>
    /// <param name="dbName">
    /// The name of the attached database to query.
    /// </param>
    /// <returns>
    /// The fully qualified path and file name for the currently open database,
    /// if any.
    /// </returns>
    internal abstract string GetFileName(string dbName);
    /// <summary>
    /// Opens a database.
    /// </summary>
    /// <remarks>
    /// Implementers should call SQLiteFunction.BindFunctions() and save the array after opening a connection
    /// to bind all attributed user-defined functions and collating sequences to the new connection.
    /// </remarks>
Changes to System.Data.SQLite/SQLiteConnection.cs.
2024
2025
2026
2027
2028
2029
2030





















2031
2032
2033
2034
2035
2036
2037
    {
      get
      {
        CheckDisposed();
        return _dataSource;
      }
    }






















    /// <summary>
    /// Returns the string "main".
    /// </summary>
#if !PLATFORM_COMPACTFRAMEWORK
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
#endif







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
    {
      get
      {
        CheckDisposed();
        return _dataSource;
      }
    }

    /// <summary>
    /// Returns the fully qualified path and file name for the currently open
    /// database, if any.
    /// </summary>
#if !PLATFORM_COMPACTFRAMEWORK
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
#endif
    public string FileName
    {
        get
        {
            CheckDisposed();

            if (_sql == null)
                throw new InvalidOperationException(
                    "Database connection not valid for getting file name.");

            return _sql.GetFileName("main");
        }
    }

    /// <summary>
    /// Returns the string "main".
    /// </summary>
#if !PLATFORM_COMPACTFRAMEWORK
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
#endif
Changes to Tests/basic.eagle.
3850
3851
3852
3853
3854
3855
3856



























3857
3858
3859
3860
3861
3862
3863
  rename hashManagedArray ""
  rename getHashCode ""
  rename getMyFuncArgs ""
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -match regexp -result {^0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 \{1\
2 3 A a M m Z z\} True 1 True 1 True 1 True 1 True 1 True 1 True 1 True 1\
\{(?:-)?\d+ (?:-)?\d+\}$}}




























###############################################################################

reportSQLiteResources $test_channel

###############################################################################








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
  rename hashManagedArray ""
  rename getHashCode ""
  rename getMyFuncArgs ""
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -match regexp -result {^0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 0 \{1\
2 3 A a M m Z z\} True 1 True 1 True 1 True 1 True 1 True 1 True 1 True 1\
\{(?:-)?\d+ (?:-)?\d+\}$}}

###############################################################################

set fileName(1) [file nativename \
    [file join [getDatabaseDirectory] data-1.76.db]]

###############################################################################

runTest {test data-1.76 {SQLiteConnection.FileName property} -setup {
  setupDb [set fileName(2) data-1.76.db]
} -body {
  set connection [getDbConnection]
  $connection FileName
} -cleanup {
  freeDbConnection

  unset -nocomplain connection

  cleanupDb $fileName(2)

  unset -nocomplain db
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result $fileName(1)}

###############################################################################

unset -nocomplain fileName

###############################################################################

reportSQLiteResources $test_channel

###############################################################################