2008-02-25 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.Security / SqliteRoleProvider.cs
1 //
2 // $Id: PgRoleProvider.cs 12 2007-10-17 17:22:43Z dna $
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright © 2006, 2007 Nauck IT KG           http://www.nauck-it.de
24 //
25 // Author:
26 //      Daniel Nauck            <d.nauck(at)nauck-it.de>
27 //
28 // Adapted to Sqlite by Marek Habersack <mhabersack@novell.com>
29 //
30
31 #if NET_2_0
32 using System;
33 using System.Data;
34 using System.Data.Common;
35 using System.Collections.Generic;
36 using System.Collections.Specialized;
37 using System.Diagnostics;
38 using System.Text;
39 using System.Configuration;
40 using System.Configuration.Provider;
41 using System.Web.Hosting;
42 using System.Web.Security;
43
44 using Mono.Data.Sqlite;
45
46 namespace System.Web.Security
47 {
48         internal class SqliteRoleProvider : RoleProvider
49         {
50                 private const string m_RolesTableName = "Roles";
51                 private const string m_UserInRolesTableName = "UsersInRoles";
52                 private string m_ConnectionString = string.Empty;
53
54                 DbParameter AddParameter (DbCommand command, string parameterName)
55                 {
56                         return AddParameter (command, parameterName, null);
57                 }
58                 
59                 DbParameter AddParameter (DbCommand command, string parameterName, object parameterValue)
60                 {
61                         return AddParameter (command, parameterName, ParameterDirection.Input, parameterValue);
62                 }
63
64                 DbParameter AddParameter (DbCommand command, string parameterName, ParameterDirection direction, object parameterValue)
65                 {
66                         DbParameter dbp = command.CreateParameter ();
67                         dbp.ParameterName = parameterName;
68                         dbp.Value = parameterValue;
69                         dbp.Direction = direction;
70                         command.Parameters.Add (dbp);
71                         return dbp;
72                 }
73
74                 DbParameter AddParameter (DbCommand command, string parameterName, ParameterDirection direction, DbType type, object parameterValue)
75                 {
76                         DbParameter dbp = command.CreateParameter ();
77                         dbp.ParameterName = parameterName;
78                         dbp.Value = parameterValue;
79                         dbp.Direction = direction;
80                         dbp.DbType = type;
81                         command.Parameters.Add (dbp);
82                         return dbp;
83                 }
84                 
85                 /// <summary>
86                 /// System.Configuration.Provider.ProviderBase.Initialize Method
87                 /// </summary>
88                 public override void Initialize(string name, NameValueCollection config)
89                 {
90                         // Initialize values from web.config.
91                         if (config == null)
92                                 throw new ArgumentNullException("Config", Properties.Resources.ErrArgumentNull);
93
94                         if (string.IsNullOrEmpty(name))
95                                 name = Properties.Resources.RoleProviderDefaultName;
96
97                         if (string.IsNullOrEmpty(config["description"]))
98                         {
99                                 config.Remove("description");
100                                 config.Add("description", Properties.Resources.RoleProviderDefaultDescription);
101                         }
102
103                         // Initialize the abstract base class.
104                         base.Initialize(name, config);
105
106                         m_ApplicationName = GetConfigValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath);
107
108                         // Get connection string.
109                         string connStrName = config["connectionStringName"];
110
111                         if (string.IsNullOrEmpty(connStrName))
112                         {
113                                 throw new ArgumentOutOfRangeException("ConnectionStringName", Properties.Resources.ErrArgumentNullOrEmpty);
114                         }
115                         else
116                         {
117                                 ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[connStrName];
118
119                                 if (ConnectionStringSettings == null || string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
120                                 {
121                                         throw new ProviderException(Properties.Resources.ErrConnectionStringNullOrEmpty);
122                                 }
123
124                                 m_ConnectionString = ConnectionStringSettings.ConnectionString;
125                         }
126                 }
127
128                 /// <summary>
129                 /// System.Web.Security.RoleProvider properties.
130                 /// </summary>
131                 #region System.Web.Security.RoleProvider properties
132                 private string m_ApplicationName = string.Empty;
133
134                 public override string ApplicationName
135                 {
136                         get { return m_ApplicationName; }
137                         set { m_ApplicationName = value; }
138                 }
139                 #endregion
140
141                 /// <summary>
142                 /// System.Web.Security.RoleProvider methods.
143                 /// </summary>
144                 #region System.Web.Security.RoleProvider methods
145
146                 /// <summary>
147                 /// RoleProvider.AddUsersToRoles
148                 /// </summary>
149                 public override void AddUsersToRoles(string[] userNames, string[] roleNames)
150                 {
151                         foreach (string rolename in roleNames)
152                         {
153                                 if (!RoleExists(rolename))
154                                 {
155                                         throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, rolename));
156                                 }
157                         }
158
159                         foreach (string username in userNames)
160                         {
161                                 foreach (string rolename in roleNames)
162                                 {
163                                         if (IsUserInRole(username, rolename))
164                                         {
165                                                 throw new ProviderException(string.Format(Properties.Resources.ErrUserAlreadyInRole, username, rolename));
166                                         }
167                                 }
168                         }
169
170                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
171                         {
172                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
173                                 {
174                                         dbCommand.CommandText = string.Format("INSERT INTO \"{0}\" (\"Username\", \"Rolename\", \"ApplicationName\") Values (@Username, @Rolename, @ApplicationName)", m_UserInRolesTableName);
175
176                                         AddParameter (dbCommand, "@Username");
177                                         AddParameter (dbCommand, "@Rolename");
178                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
179
180                                         SqliteTransaction dbTrans = null;
181
182                                         try
183                                         {
184                                                 dbConn.Open();
185                                                 dbCommand.Prepare();
186
187                                                 using (dbTrans = dbConn.BeginTransaction())
188                                                 {
189                                                         foreach (string username in userNames)
190                                                         {
191                                                                 foreach (string rolename in roleNames)
192                                                                 {
193                                                                         dbCommand.Parameters["@Username"].Value = username;
194                                                                         dbCommand.Parameters["@Rolename"].Value = rolename;
195                                                                         dbCommand.ExecuteNonQuery();
196                                                                 }
197                                                         }
198                                                         // Attempt to commit the transaction
199                                                         dbTrans.Commit();
200                                                 }
201                                         }
202                                         catch (SqliteException e)
203                                         {
204                                                 Trace.WriteLine(e.ToString());
205
206                                                 try
207                                                 {
208                                                         // Attempt to roll back the transaction
209                                                         Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
210                                                         dbTrans.Rollback();
211                                                 }
212                                                 catch (SqliteException re)
213                                                 {
214                                                         // Rollback failed
215                                                         Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
216                                                         Trace.WriteLine(re.ToString());
217                                                 }
218
219                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
220                                         }
221                                         finally
222                                         {
223                                                 if (dbConn != null)
224                                                         dbConn.Close();
225                                         }
226                                 }
227                         }
228                 }
229
230                 /// <summary>
231                 /// RoleProvider.CreateRole
232                 /// </summary>
233                 public override void CreateRole(string roleName)
234                 {
235                         if (RoleExists(roleName))
236                         {
237                                 throw new ProviderException(string.Format(Properties.Resources.ErrRoleAlreadyExist, roleName));
238                         }
239
240                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
241                         {
242                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
243                                 {
244                                         dbCommand.CommandText = string.Format("INSERT INTO \"{0}\" (\"Rolename\", \"ApplicationName\") Values (@Rolename, @ApplicationName)", m_RolesTableName);
245
246                                         AddParameter (dbCommand, "@Rolename", roleName);
247                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
248
249                                         try
250                                         {
251                                                 dbConn.Open();
252                                                 dbCommand.Prepare();
253
254                                                 dbCommand.ExecuteNonQuery();
255                                         }
256                                         catch (SqliteException e)
257                                         {
258                                                 Trace.WriteLine(e.ToString());
259                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
260                                         }
261                                         finally
262                                         {
263                                                 if (dbConn != null)
264                                                         dbConn.Close();
265                                         }
266                                 }
267                         }
268                 }
269
270                 /// <summary>
271                 /// RoleProvider.DeleteRole
272                 /// </summary>
273                 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
274                 {
275                         if (!RoleExists(roleName))
276                         {
277                                 throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, roleName));
278                         }
279
280                         if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0)
281                         {
282                                 throw new ProviderException(Properties.Resources.ErrCantDeletePopulatedRole);
283                         }
284
285                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
286                         {
287                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
288                                 {
289                                         dbCommand.CommandText = string.Format("DELETE FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_RolesTableName);
290
291                                         AddParameter (dbCommand, "@Rolename", roleName);
292                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
293
294                                         SqliteTransaction dbTrans = null;
295
296                                         try
297                                         {
298                                                 dbConn.Open();
299                                                 dbCommand.Prepare();
300
301                                                 using (dbTrans = dbConn.BeginTransaction())
302                                                 {
303                                                         dbCommand.ExecuteNonQuery();
304
305                                                         // Attempt to commit the transaction
306                                                         dbTrans.Commit();
307                                                 }
308                                         }
309                                         catch (SqliteException e)
310                                         {
311                                                 Trace.WriteLine(e.ToString());
312
313                                                 try
314                                                 {
315                                                         // Attempt to roll back the transaction
316                                                         Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
317                                                         dbTrans.Rollback();
318                                                 }
319                                                 catch (SqliteException re)
320                                                 {
321                                                         // Rollback failed
322                                                         Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
323                                                         Trace.WriteLine(re.ToString());
324                                                 }
325
326                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
327                                         }
328                                         finally
329                                         {
330                                                 if (dbConn != null)
331                                                         dbConn.Close();
332                                         }
333                                 }
334                         }
335
336                         return true;
337                 }
338
339                 /// <summary>
340                 /// RoleProvider.FindUsersInRole
341                 /// </summary>
342                 public override string[] FindUsersInRole(string roleName, string usernameToMatch)
343                 {
344                         List<string> userList = new List<string>();
345
346                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
347                         {
348                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
349                                 {
350                                         dbCommand.CommandText = string.Format("SELECT \"Username\" FROM \"{0}\" WHERE \"Username\" LIKE @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName ORDER BY \"Username\" ASC", m_UserInRolesTableName);
351
352                                         AddParameter (dbCommand, "@Username", usernameToMatch);
353                                         AddParameter (dbCommand, "@Rolename", roleName);
354                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
355
356                                         try
357                                         {
358                                                 dbConn.Open();
359                                                 dbCommand.Prepare();
360
361                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
362                                                 {
363                                                         if (reader.HasRows)
364                                                         {
365                                                                 while (reader.Read())
366                                                                 {
367                                                                         userList.Add(reader.GetString(0));
368                                                                 }
369                                                         }
370                                                 }
371                                         }
372                                         catch (SqliteException e)
373                                         {
374                                                 Trace.WriteLine(e.ToString());
375                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
376                                         }
377                                         finally
378                                         {
379                                                 if (dbConn != null)
380                                                         dbConn.Close();
381                                         }
382                                 }
383                         }
384
385                         return userList.ToArray();
386                 }
387
388                 /// <summary>
389                 /// RoleProvider.GetAllRoles
390                 /// </summary>
391                 public override string[] GetAllRoles()
392                 {
393                         List<string> rolesList = new List<string>();
394
395                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
396                         {
397                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
398                                 {
399                                         dbCommand.CommandText = string.Format("SELECT \"Rolename\" FROM \"{0}\" WHERE \"ApplicationName\" = @ApplicationName ORDER BY \"Rolename\" ASC", m_RolesTableName);
400
401                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
402
403                                         try
404                                         {
405                                                 dbConn.Open();
406                                                 dbCommand.Prepare();
407
408                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
409                                                 {
410                                                         while (reader.Read())
411                                                         {
412                                                                 rolesList.Add(reader.GetString(0));
413                                                         }
414                                                 }                                               
415                                         }
416                                         catch (SqliteException e)
417                                         {
418                                                 Trace.WriteLine(e.ToString());
419                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
420                                         }
421                                         finally
422                                         {
423                                                 if (dbConn != null)
424                                                         dbConn.Close();
425                                         }
426                                 }
427                         }
428
429                         return rolesList.ToArray();
430                 }
431
432                 /// <summary>
433                 /// RoleProvider.GetRolesForUser
434                 /// </summary>
435                 public override string[] GetRolesForUser(string username)
436                 {
437                         List<string> rolesList = new List<string>();
438
439                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
440                         {
441                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
442                                 {
443                                         dbCommand.CommandText = string.Format("SELECT \"Rolename\" FROM \"{0}\" WHERE \"Username\" = @Username AND \"ApplicationName\" = @ApplicationName ORDER BY \"Rolename\" ASC", m_UserInRolesTableName);
444
445                                         AddParameter (dbCommand, "@Username", username);
446                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
447
448                                         try
449                                         {
450                                                 dbConn.Open();
451                                                 dbCommand.Prepare();
452
453                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
454                                                 {
455                                                         if (reader.HasRows)
456                                                         {
457                                                                 while (reader.Read())
458                                                                 {
459                                                                         rolesList.Add(reader.GetString(0));
460                                                                 }
461                                                         }
462                                                 }
463                                         }
464                                         catch (SqliteException e)
465                                         {
466                                                 Trace.WriteLine(e.ToString());
467                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
468                                         }
469                                         finally
470                                         {
471                                                 if (dbConn != null)
472                                                         dbConn.Close();
473                                         }
474                                 }
475                         }
476
477                         return rolesList.ToArray();
478                 }
479
480                 /// <summary>
481                 /// RoleProvider.GetUsersInRole
482                 /// </summary>
483                 public override string[] GetUsersInRole(string roleName)
484                 {
485                         List<string> userList = new List<string>();
486
487                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
488                         {
489                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
490                                 {
491                                         dbCommand.CommandText = string.Format("SELECT \"Username\" FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName ORDER BY \"Username\" ASC", m_UserInRolesTableName);
492
493                                         AddParameter (dbCommand, "@Rolename", roleName);
494                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
495
496                                         try
497                                         {
498                                                 dbConn.Open();
499                                                 dbCommand.Prepare();
500
501                                                 using (SqliteDataReader reader = dbCommand.ExecuteReader())
502                                                 {
503                                                         if (reader.HasRows)
504                                                         {
505                                                                 while (reader.Read())
506                                                                 {
507                                                                         userList.Add(reader.GetString(0));
508                                                                 }
509                                                         }
510                                                 }
511                                         }
512                                         catch (SqliteException e)
513                                         {
514                                                 Trace.WriteLine(e.ToString());
515                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
516                                         }
517                                         finally
518                                         {
519                                                 if (dbConn != null)
520                                                         dbConn.Close();
521                                         }
522                                 }
523                         }
524
525                         return userList.ToArray();
526                 }
527
528                 /// <summary>
529                 /// RoleProvider.IsUserInRole
530                 /// </summary>
531                 public override bool IsUserInRole(string userName, string roleName)
532                 {
533                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
534                         {
535                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
536                                 {
537                                         dbCommand.CommandText = string.Format("SELECT COUNT(*) FROM \"{0}\" WHERE \"Username\" = @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_UserInRolesTableName);
538
539                                         AddParameter (dbCommand, "@Username", userName);
540                                         AddParameter (dbCommand, "@Rolename", roleName);
541                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
542
543                                         try
544                                         {
545                                                 dbConn.Open();
546                                                 dbCommand.Prepare();
547
548                                                 int numRecs = 0;
549                                                 Int32.TryParse(dbCommand.ExecuteScalar().ToString(), out numRecs);
550
551                                                 if (numRecs > 0)
552                                                         return true;
553                                         }
554                                         catch (SqliteException e)
555                                         {
556                                                 Trace.WriteLine(e.ToString());
557                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
558                                         }
559                                         finally
560                                         {
561                                                 if (dbConn != null)
562                                                         dbConn.Close();
563                                         }
564                                 }
565                         }
566
567                         return false;
568                 }
569
570                 /// <summary>
571                 /// RoleProvider.RemoveUsersFromRoles
572                 /// </summary>
573                 public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
574                 {
575                         foreach (string rolename in roleNames)
576                         {
577                                 if (!RoleExists(rolename))
578                                 {
579                                         throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, rolename));
580                                 }
581                         }
582
583                         foreach (string username in userNames)
584                         {
585                                 foreach (string rolename in roleNames)
586                                 {
587                                         if (!IsUserInRole(username, rolename))
588                                         {
589                                                 throw new ProviderException(string.Format(Properties.Resources.ErrUserIsNotInRole, username, rolename));
590                                         }
591                                 }
592                         }
593
594                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
595                         {
596                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
597                                 {
598                                         dbCommand.CommandText = string.Format("DELETE FROM \"{0}\" WHERE \"Username\" = @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_UserInRolesTableName);
599
600                                         AddParameter (dbCommand, "@Username");
601                                         AddParameter (dbCommand, "@Rolename");
602                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
603
604                                         SqliteTransaction dbTrans = null;
605
606                                         try
607                                         {
608                                                 dbConn.Open();
609                                                 dbCommand.Prepare();
610
611                                                 using (dbTrans = dbConn.BeginTransaction())
612                                                 {
613                                                         foreach (string username in userNames)
614                                                         {
615                                                                 foreach (string rolename in roleNames)
616                                                                 {
617                                                                         dbCommand.Parameters["@Username"].Value = username;
618                                                                         dbCommand.Parameters["@Rolename"].Value = rolename;
619                                                                         dbCommand.ExecuteNonQuery();
620                                                                 }
621                                                         }
622                                                         // Attempt to commit the transaction
623                                                         dbTrans.Commit();
624                                                 }
625                                         }
626                                         catch (SqliteException e)
627                                         {
628                                                 Trace.WriteLine(e.ToString());
629
630                                                 try
631                                                 {
632                                                         // Attempt to roll back the transaction
633                                                         Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
634                                                         dbTrans.Rollback();
635                                                 }
636                                                 catch (SqliteException re)
637                                                 {
638                                                         // Rollback failed
639                                                         Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
640                                                         Trace.WriteLine(re.ToString());
641                                                 }
642
643                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
644                                         }
645                                         finally
646                                         {
647                                                 if (dbConn != null)
648                                                         dbConn.Close();
649                                         }
650                                 }
651                         }
652                 }
653
654                 /// <summary>
655                 /// RoleProvider.RoleExists
656                 /// </summary>
657                 public override bool RoleExists(string roleName)
658                 {
659                         using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
660                         {
661                                 using (SqliteCommand dbCommand = dbConn.CreateCommand())
662                                 {
663                                         dbCommand.CommandText = string.Format("SELECT COUNT(*) FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_RolesTableName);
664
665                                         AddParameter (dbCommand, "@Rolename", roleName);
666                                         AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
667
668                                         try
669                                         {
670                                                 dbConn.Open();
671                                                 dbCommand.Prepare();
672
673                                                 int numRecs = 0;
674                                                 Int32.TryParse(dbCommand.ExecuteScalar().ToString(), out numRecs);
675
676                                                 if (numRecs > 0)
677                                                         return true;
678                                         }
679                                         catch (SqliteException e)
680                                         {
681                                                 Trace.WriteLine(e.ToString());
682                                                 throw new ProviderException(Properties.Resources.ErrOperationAborted);
683                                         }
684                                         finally
685                                         {
686                                                 if (dbConn != null)
687                                                         dbConn.Close();
688                                         }
689                                 }
690                         }
691
692                         return false;
693                 }
694                 #endregion
695
696                 #region private methods
697                 /// <summary>
698                 /// A helper function to retrieve config values from the configuration file.
699                 /// </summary>
700                 /// <param name="configValue"></param>
701                 /// <param name="defaultValue"></param>
702                 /// <returns></returns>
703                 private string GetConfigValue(string configValue, string defaultValue)
704                 {
705                         if (string.IsNullOrEmpty(configValue))
706                                 return defaultValue;
707
708                         return configValue;
709                 }
710                 #endregion      
711         }
712 }
713 #endif