System.Data.SQLite

Check-in [1d024437e5]
Login

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

Overview
Comment:Preliminary fix for [b4a7ddc83f], shutdown the SQLite native interface when the AppDomain is being unloaded.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1d024437e53cdfbf99f3eb469440485c4130a130
User & Date: mistachkin 2011-07-21 17:18:30.794
References
2011-07-21
21:48 Closed ticket [b4a7ddc83f]: Exception when reloading IIS application plus 4 other changes artifact: b2ecb59f9a user: mistachkin
Context
2011-07-21
21:46
Add comment to warn about the nature of the current fix for [b4a7ddc83f]. check-in: f5c5f581dc user: mistachkin tags: trunk
17:18
Preliminary fix for [b4a7ddc83f], shutdown the SQLite native interface when the AppDomain is being unloaded. check-in: 1d024437e5 user: mistachkin tags: trunk
17:15
Update test case for [b4a7ddc83f]. check-in: 10f4be9ed4 user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLiteLog.cs.
105
106
107
108
109
110
111









112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144


























145
146
147
148
149
150
151
        /// Initializes the SQLite logging facilities.
        /// </summary>
        public static void Initialize()
        {
            lock (syncRoot)
            {
                //









                // NOTE: Create a single "global" 
                //
                if (_sql == null)
                    _sql = new SQLite3(SQLiteDateFormats.ISO8601);

                //
                // NOTE: Create a single "global" (i.e. per-process) callback
                //       to register with SQLite.  This callback will pass the
                //       event on to any registered handler.  We only want to
                //       do this once.
                //
                if (_callback == null)
                {
                    _callback = new SQLiteLogCallback(LogCallback);

                    int rc = _sql.SetLogCallback(_callback);

                    if (rc != 0)
                        throw new SQLiteException(rc,
                            "Failed to initialize logging interface.");
                }

                //
                // NOTE: Logging is enabled by default.
                //
                _enabled = true;

                //
                // NOTE: For now, always setup the default log event handler.
                //
                AddDefaultHandler();
            }
        }



























        /// <summary>
        /// This event is raised whenever SQLite raises a logging event.
        /// Note that this should be set as one of the first things in the
        /// application.
        /// </summary>
        public static event SQLiteLogEventHandler Log







>
>
>
>
>
>
>
>
>
|


|















|













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







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
        /// Initializes the SQLite logging facilities.
        /// </summary>
        public static void Initialize()
        {
            lock (syncRoot)
            {
                //
                // NOTE: Add an event handler for the DomainUnload event so
                //       that we can unhook our logging managed function
                //       pointer from the native SQLite code prior to it
                //       being invalidated.
                //
                AppDomain.CurrentDomain.DomainUnload +=
                    new EventHandler(DomainUnload);

                //
                // NOTE: Create an instance of the SQLite wrapper class.
                //
                if (_sql == null)
                    _sql = new SQLite3(SQLiteDateFormats.Default);

                //
                // NOTE: Create a single "global" (i.e. per-process) callback
                //       to register with SQLite.  This callback will pass the
                //       event on to any registered handler.  We only want to
                //       do this once.
                //
                if (_callback == null)
                {
                    _callback = new SQLiteLogCallback(LogCallback);

                    int rc = _sql.SetLogCallback(_callback);

                    if (rc != 0)
                        throw new SQLiteException(rc,
                            "Failed to initialize logging.");
                }

                //
                // NOTE: Logging is enabled by default.
                //
                _enabled = true;

                //
                // NOTE: For now, always setup the default log event handler.
                //
                AddDefaultHandler();
            }
        }

        /// <summary>
        /// Handles the AppDomain being unloaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void DomainUnload(
            object sender,
            EventArgs e
            )
        {
            if (_sql != null)
            {
                int rc = _sql.Shutdown();

                if (rc != 0)
                    throw new SQLiteException(rc,
                        "Failed to shutdown interface.");

                rc = _sql.SetLogCallback(null);

                if (rc != 0)
                    throw new SQLiteException(rc,
                        "Failed to shutdown logging.");
            }
        }

        /// <summary>
        /// This event is raised whenever SQLite raises a logging event.
        /// Note that this should be set as one of the first things in the
        /// application.
        /// </summary>
        public static event SQLiteLogEventHandler Log
Changes to Tests/tkt-b4a7ddc83f.eagle.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package require EagleLibrary
package require EagleTest

runTestPrologue

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

# set ::test_configuration Debug

source [file join $path common.eagle]
runSQLiteTestPrologue

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

runTest {test tkt-b4a7ddc83f-1.1 {initialization/shutdown} -setup [subst {
  set fileName tkt-b4a7ddc83f-1.1.db
  set ::path {$::path}
  set ::test_configuration {$::test_configuration}
  source [file join $::path common.eagle]
}] -body {
  package require EagleTest
  tryLoadAssembly System.Data.SQLite.dll
  object invoke System.Data.SQLite.SQLiteLog Initialize
  setupDb $fileName
} -cleanup {
  cleanupDb $fileName
  unset -nocomplain db fileName
} -constraints {eagle monoBug28 command.sql compile.DATA\
compile.ISOLATED_INTERPRETERS System.Data.SQLite} -isolationLevel AppDomain \
-match regexp -result {^SQLiteConnection#\d+$}}

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

runTest {test tkt-b4a7ddc83f-1.2 {initialization/shutdown} -setup [subst {
  set fileName tkt-b4a7ddc83f-1.2.db
  set ::path {$::path}
  set ::test_configuration {$::test_configuration}
  source [file join $::path common.eagle]
}] -body {
  package require EagleTest
  tryLoadAssembly System.Data.SQLite.dll







<
<





|


















|







11
12
13
14
15
16
17


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package require EagleLibrary
package require EagleTest

runTestPrologue

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



source [file join $path common.eagle]
runSQLiteTestPrologue

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

runTest {test tkt-b4a7ddc83f-1.1 {logging shutdown, step 1} -setup [subst {
  set fileName tkt-b4a7ddc83f-1.1.db
  set ::path {$::path}
  set ::test_configuration {$::test_configuration}
  source [file join $::path common.eagle]
}] -body {
  package require EagleTest
  tryLoadAssembly System.Data.SQLite.dll
  object invoke System.Data.SQLite.SQLiteLog Initialize
  setupDb $fileName
} -cleanup {
  cleanupDb $fileName
  unset -nocomplain db fileName
} -constraints {eagle monoBug28 command.sql compile.DATA\
compile.ISOLATED_INTERPRETERS System.Data.SQLite} -isolationLevel AppDomain \
-match regexp -result {^SQLiteConnection#\d+$}}

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

runTest {test tkt-b4a7ddc83f-1.2 {logging shutdown, step 2} -setup [subst {
  set fileName tkt-b4a7ddc83f-1.2.db
  set ::path {$::path}
  set ::test_configuration {$::test_configuration}
  source [file join $::path common.eagle]
}] -body {
  package require EagleTest
  tryLoadAssembly System.Data.SQLite.dll