System.Data.SQLite
Check-in [e28ff15b0e]
Not logged in

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

Overview
Comment:Add a new overload for the SQLiteBlob.Create method that is a thinner wrapper over the native API, for greater efficiency. Pursuant to [dfc8133ba2].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e28ff15b0e6ad569caa7abc7a98272fbe1054784
User & Date: mistachkin 2018-04-18 15:27:56
Context
2018-04-18
15:48
Update version history docs. check-in: 6f0089d0c2 user: mistachkin tags: trunk
15:27
Add a new overload for the SQLiteBlob.Create method that is a thinner wrapper over the native API, for greater efficiency. Pursuant to [dfc8133ba2]. check-in: e28ff15b0e user: mistachkin tags: trunk
2018-04-13
12:56
Update SQLite core library to the 3.23.1 release. check-in: a6429adaa8 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

    70     70           /// </returns>
    71     71           public static SQLiteBlob Create(
    72     72               SQLiteDataReader dataReader,
    73     73               int i,
    74     74               bool readOnly
    75     75               )
    76     76           {
    77         -            SQLiteConnection connection = SQLiteDataReader.GetConnection(
    78         -                dataReader);
           77  +            if (dataReader == null)
           78  +                throw new ArgumentNullException("dataReader");
    79     79   
           80  +            long? rowId = dataReader.GetRowId(i);
           81  +
           82  +            if (rowId == null)
           83  +                throw new InvalidOperationException("No RowId is available");
           84  +
           85  +            return Create(
           86  +                SQLiteDataReader.GetConnection(dataReader),
           87  +                dataReader.GetDatabaseName(i), dataReader.GetTableName(i),
           88  +                dataReader.GetName(i), (long)rowId, readOnly);
           89  +        }
           90  +
           91  +        ///////////////////////////////////////////////////////////////////////////////////////////////
           92  +
           93  +        /// <summary>
           94  +        /// Creates a <see cref="SQLiteBlob" /> object.  This will not work
           95  +        /// for tables that were created WITHOUT ROWID.
           96  +        /// </summary>
           97  +        /// <param name="connection">
           98  +        /// The connection to use when opening the blob object.
           99  +        /// </param>
          100  +        /// <param name="databaseName">
          101  +        /// The name of the database containing the blob object.
          102  +        /// </param>
          103  +        /// <param name="tableName">
          104  +        /// The name of the table containing the blob object.
          105  +        /// </param>
          106  +        /// <param name="columnName">
          107  +        /// The name of the column containing the blob object.
          108  +        /// </param>
          109  +        /// <param name="rowId">
          110  +        /// The integer identifier for the row associated with the desired
          111  +        /// blob object.
          112  +        /// </param>
          113  +        /// <param name="readOnly">
          114  +        /// Non-zero to open the blob object for read-only access.
          115  +        /// </param>
          116  +        /// <returns>
          117  +        /// The newly created <see cref="SQLiteBlob" /> instance -OR- null
          118  +        /// if an error occurs.
          119  +        /// </returns>
          120  +        public static SQLiteBlob Create(
          121  +            SQLiteConnection connection,
          122  +            string databaseName,
          123  +            string tableName,
          124  +            string columnName,
          125  +            long rowId,
          126  +            bool readOnly
          127  +            )
          128  +        {
    80    129               if (connection == null)
    81         -                throw new InvalidOperationException("Connection not available");
          130  +                throw new ArgumentNullException("connection");
    82    131   
    83    132               SQLite3 sqlite3 = connection._sql as SQLite3;
    84    133   
    85    134               if (sqlite3 == null)
    86    135                   throw new InvalidOperationException("Connection has no wrapper");
    87    136   
    88    137               SQLiteConnectionHandle handle = sqlite3._sql;
    89    138   
    90    139               if (handle == null)
    91    140                   throw new InvalidOperationException("Connection has an invalid handle.");
    92    141   
    93         -            long? rowId = dataReader.GetRowId(i);
    94         -
    95         -            if (rowId == null)
    96         -                throw new InvalidOperationException("No RowId is available");
    97         -
    98    142               SQLiteBlobHandle blob = null;
    99    143   
   100    144               try
   101    145               {
   102    146                   // do nothing.
   103    147               }
   104    148               finally /* NOTE: Thread.Abort() protection. */
   105    149               {
   106    150                   IntPtr ptrBlob = IntPtr.Zero;
   107    151   
   108    152                   SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3_blob_open(
   109         -                    handle, SQLiteConvert.ToUTF8(
   110         -                        dataReader.GetDatabaseName(i)), SQLiteConvert.ToUTF8(
   111         -                    dataReader.GetTableName(i)), SQLiteConvert.ToUTF8(
   112         -                        dataReader.GetName(i)), (long)rowId, readOnly ? 0 : 1,
   113         -                    ref ptrBlob);
          153  +                    handle, SQLiteConvert.ToUTF8(databaseName),
          154  +                    SQLiteConvert.ToUTF8(tableName), SQLiteConvert.ToUTF8(
          155  +                    columnName), rowId, readOnly ? 0 : 1, ref ptrBlob);
   114    156   
   115    157                   if (rc != SQLiteErrorCode.Ok)
   116    158                       throw new SQLiteException(rc, null);
   117    159   
   118    160                   blob = new SQLiteBlobHandle(handle, ptrBlob);
   119    161               }
   120    162   
   121         -            SQLiteConnection.OnChanged(null, new ConnectionEventArgs(
   122         -                SQLiteConnectionEventType.NewCriticalHandle, null,
   123         -                null, null, dataReader, blob, null, new object[] {
   124         -                typeof(SQLiteBlob), dataReader, i, readOnly }));
          163  +            SQLiteConnection.OnChanged(connection, new ConnectionEventArgs(
          164  +                SQLiteConnectionEventType.NewCriticalHandle, null, null,
          165  +                null, null, blob, null, new object[] { typeof(SQLiteBlob),
          166  +                databaseName, tableName, columnName, rowId, readOnly }));
   125    167   
   126    168               return new SQLiteBlob(sqlite3, blob);
   127    169           }
   128    170           #endregion
   129    171   
   130    172           ///////////////////////////////////////////////////////////////////////////////////////////////
   131    173