1.Dd December 19, 2018 2.Dt SQLITE3CHANGESET_APPLY_STRM 3 3.Os 4.Sh NAME 5.Nm sqlite3changeset_apply_strm , 6.Nm sqlite3changeset_apply_v2_strm , 7.Nm sqlite3changeset_concat_strm , 8.Nm sqlite3changeset_invert_strm , 9.Nm sqlite3changeset_start_strm , 10.Nm sqlite3changeset_start_v2_strm , 11.Nm sqlite3session_changeset_strm , 12.Nm sqlite3session_patchset_strm , 13.Nm sqlite3changegroup_add_strm , 14.Nm sqlite3changegroup_output_strm , 15.Nm sqlite3rebaser_rebase_strm 16.Nd Streaming Versions of API functions. 17.Sh SYNOPSIS 18.Ft int 19.Fo sqlite3changeset_apply_strm 20.Fa "sqlite3 *db" 21.Fa "int (*xInput)(void *pIn, void *pData, int *pnData)" 22.Fa "void *pIn" 23.Fa "int(*xFilter)( void *pCtx, const char *zTab )" 24.Fa "int(*xConflict)( void *pCtx, int eConflict, sqlite3_changeset_iter *p )" 25.Fa "void *pCtx " 26.Fc 27.Ft int 28.Fo sqlite3changeset_apply_v2_strm 29.Fa "sqlite3 *db" 30.Fa "int (*xInput)(void *pIn, void *pData, int *pnData)" 31.Fa "void *pIn" 32.Fa "int(*xFilter)( void *pCtx, const char *zTab )" 33.Fa "int(*xConflict)( void *pCtx, int eConflict, sqlite3_changeset_iter *p )" 34.Fa "void *pCtx" 35.Fa "void **ppRebase" 36.Fa "int *pnRebase" 37.Fa "int flags " 38.Fc 39.Ft int 40.Fo sqlite3changeset_concat_strm 41.Fa "int (*xInputA)(void *pIn, void *pData, int *pnData)" 42.Fa "void *pInA" 43.Fa "int (*xInputB)(void *pIn, void *pData, int *pnData)" 44.Fa "void *pInB" 45.Fa "int (*xOutput)(void *pOut, const void *pData, int nData)" 46.Fa "void *pOut " 47.Fc 48.Ft int 49.Fo sqlite3changeset_invert_strm 50.Fa "int (*xInput)(void *pIn, void *pData, int *pnData)" 51.Fa "void *pIn" 52.Fa "int (*xOutput)(void *pOut, const void *pData, int nData)" 53.Fa "void *pOut " 54.Fc 55.Ft int 56.Fo sqlite3changeset_start_strm 57.Fa "sqlite3_changeset_iter **pp" 58.Fa "int (*xInput)(void *pIn, void *pData, int *pnData)" 59.Fa "void *pIn " 60.Fc 61.Ft int 62.Fo sqlite3changeset_start_v2_strm 63.Fa "sqlite3_changeset_iter **pp" 64.Fa "int (*xInput)(void *pIn, void *pData, int *pnData)" 65.Fa "void *pIn" 66.Fa "int flags " 67.Fc 68.Ft int 69.Fo sqlite3session_changeset_strm 70.Fa "sqlite3_session *pSession" 71.Fa "int (*xOutput)(void *pOut, const void *pData, int nData)" 72.Fa "void *pOut " 73.Fc 74.Ft int 75.Fo sqlite3session_patchset_strm 76.Fa "sqlite3_session *pSession" 77.Fa "int (*xOutput)(void *pOut, const void *pData, int nData)" 78.Fa "void *pOut " 79.Fc 80.Ft int 81.Fo sqlite3changegroup_add_strm 82.Fa "sqlite3_changegroup*" 83.Fa "int (*xInput)(void *pIn, void *pData, int *pnData)" 84.Fa "void *pIn " 85.Fc 86.Ft int 87.Fo sqlite3changegroup_output_strm 88.Fa "sqlite3_changegroup*" 89.Fa "int (*xOutput)(void *pOut, const void *pData, int nData)" 90.Fa "void *pOut " 91.Fc 92.Ft int 93.Fo sqlite3rebaser_rebase_strm 94.Fa "sqlite3_rebaser *pRebaser" 95.Fa "int (*xInput)(void *pIn, void *pData, int *pnData)" 96.Fa "void *pIn" 97.Fa "int (*xOutput)(void *pOut, const void *pData, int nData)" 98.Fa "void *pOut " 99.Fc 100.Sh DESCRIPTION 101The six streaming API xxx_strm() functions serve similar purposes to 102the corresponding non-streaming API functions: 103.Pp 104<table border=1 style="margin-left:8ex;margin-right:8ex"> <tr><th>Streaming 105function<th>Non-streaming equivalent</th> <tr><td>sqlite3changeset_apply_strm<td>sqlite3changeset_apply 106<tr><td>sqlite3changeset_apply_strm_v2<td>sqlite3changeset_apply_v2 107<tr><td>sqlite3changeset_concat_strm<td>sqlite3changeset_concat 108<tr><td>sqlite3changeset_invert_strm<td>sqlite3changeset_invert 109<tr><td>sqlite3changeset_start_strm<td>sqlite3changeset_start 110<tr><td>sqlite3session_changeset_strm<td>sqlite3session_changeset 111<tr><td>sqlite3session_patchset_strm<td>sqlite3session_patchset 112</table> 113.Pp 114Non-streaming functions that accept changesets (or patchsets) as input 115require that the entire changeset be stored in a single buffer in memory. 116Similarly, those that return a changeset or patchset do so by returning 117a pointer to a single large buffer allocated using sqlite3_malloc(). 118Normally this is convenient. 119However, if an application running in a low-memory environment is required 120to handle very large changesets, the large contiguous memory allocations 121required can become onerous. 122.Pp 123In order to avoid this problem, instead of a single large buffer, input 124is passed to a streaming API functions by way of a callback function 125that the sessions module invokes to incrementally request input data 126as it is required. 127In all cases, a pair of API function parameters such as 128.Bd -literal 129 int nChangeset, void *pChangeset, 130.Ed 131.Pp 132Is replaced by: 133.Bd -literal 134 int (*xInput)(void *pIn, void *pData, int *pnData), void 135*pIn, 136.Ed 137.Pp 138Each time the xInput callback is invoked by the sessions module, the 139first argument passed is a copy of the supplied pIn context pointer. 140The second argument, pData, points to a buffer (*pnData) bytes in size. 141Assuming no error occurs the xInput method should copy up to (*pnData) 142bytes of data into the buffer and set (*pnData) to the actual number 143of bytes copied before returning SQLITE_OK. 144If the input is completely exhausted, (*pnData) should be set to zero 145to indicate this. 146Or, if an error occurs, an SQLite error code should be returned. 147In all cases, if an xInput callback returns an error, all processing 148is abandoned and the streaming API function returns a copy of the error 149code to the caller. 150.Pp 151In the case of sqlite3changeset_start_strm(), the xInput callback may 152be invoked by the sessions module at any point during the lifetime 153of the iterator. 154If such an xInput callback returns an error, the iterator enters an 155error state, whereby all subsequent calls to iterator functions immediately 156fail with the same error code as returned by xInput. 157.Pp 158Similarly, streaming API functions that return changesets (or patchsets) 159return them in chunks by way of a callback function instead of via 160a pointer to a single large buffer. 161In this case, a pair of parameters such as: 162.Bd -literal 163 int *pnChangeset, void **ppChangeset, 164.Ed 165.Pp 166Is replaced by: 167.Bd -literal 168 int (*xOutput)(void *pOut, const void *pData, int nData), 169void *pOut 170.Ed 171.Pp 172The xOutput callback is invoked zero or more times to return data to 173the application. 174The first parameter passed to each call is a copy of the pOut pointer 175supplied by the application. 176The second parameter, pData, points to a buffer nData bytes in size 177containing the chunk of output data being returned. 178If the xOutput callback successfully processes the supplied data, it 179should return SQLITE_OK to indicate success. 180Otherwise, it should return some other SQLite error code. 181In this case processing is immediately abandoned and the streaming 182API function returns a copy of the xOutput error code to the application. 183.Pp 184The sessions module never invokes an xOutput callback with the third 185parameter set to a value less than or equal to zero. 186Other than this, no guarantees are made as to the size of the chunks 187of data returned. 188.Sh SEE ALSO 189.Xr sqlite3changeset_apply 3 , 190.Xr sqlite3changeset_concat 3 , 191.Xr sqlite3changeset_invert 3 , 192.Xr sqlite3changeset_start 3 , 193.Xr sqlite3session_changeset 3 , 194.Xr sqlite3session_patchset 3 195