SQLiteExtensions.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Data;
  3. using System.Data.SQLite;
  4. namespace MediaBrowser.Server.Sqlite
  5. {
  6. /// <summary>
  7. /// Class SQLiteExtensions
  8. /// </summary>
  9. static class SQLiteExtensions
  10. {
  11. /// <summary>
  12. /// Adds the param.
  13. /// </summary>
  14. /// <param name="cmd">The CMD.</param>
  15. /// <param name="param">The param.</param>
  16. /// <returns>SQLiteParameter.</returns>
  17. /// <exception cref="System.ArgumentNullException"></exception>
  18. public static SQLiteParameter AddParam(this SQLiteCommand cmd, string param)
  19. {
  20. if (string.IsNullOrEmpty(param))
  21. {
  22. throw new ArgumentNullException();
  23. }
  24. var sqliteParam = new SQLiteParameter(param);
  25. cmd.Parameters.Add(sqliteParam);
  26. return sqliteParam;
  27. }
  28. /// <summary>
  29. /// Adds the param.
  30. /// </summary>
  31. /// <param name="cmd">The CMD.</param>
  32. /// <param name="param">The param.</param>
  33. /// <param name="data">The data.</param>
  34. /// <returns>SQLiteParameter.</returns>
  35. /// <exception cref="System.ArgumentNullException"></exception>
  36. public static SQLiteParameter AddParam(this SQLiteCommand cmd, string param, object data)
  37. {
  38. if (string.IsNullOrEmpty(param))
  39. {
  40. throw new ArgumentNullException();
  41. }
  42. var sqliteParam = AddParam(cmd, param);
  43. sqliteParam.Value = data;
  44. return sqliteParam;
  45. }
  46. /// <summary>
  47. /// Determines whether the specified conn is open.
  48. /// </summary>
  49. /// <param name="conn">The conn.</param>
  50. /// <returns><c>true</c> if the specified conn is open; otherwise, <c>false</c>.</returns>
  51. public static bool IsOpen(this SQLiteConnection conn)
  52. {
  53. return conn.State == ConnectionState.Open;
  54. }
  55. }
  56. }