63 m_Limit= (image_limit > 1)? image_limit : (16*1024*1024);
71 size_t* bytes_written)
74 if(bytes_written) *bytes_written=
n;
78 if (bytes_written !=
NULL) {
141 if(bytes_read) *bytes_read= rn+
n;
173 if(bytes_read) *bytes_read=
n + rn;
186 const string& server,
188 const string& passwd,
222 unique_ptr<CRStream> iStream(
new CRStream(bReader.get()));
223 unique_ptr<CCompressionStreamProcessor> zProc;
240 s << zStream->rdbuf();
243 s << iStream->rdbuf();
262 const string& server,
264 const string& passwd,
285 unique_ptr<CWStream> oStream(
new CWStream(bWriter.get()));
286 unique_ptr<CCompressionStreamProcessor> zProc;
303 *zStream << s.rdbuf();
306 *oStream << s.rdbuf();
319 const string& key_col_name,
320 const string& num_col_name,
321 const string blob_column[],
325 TFlags(is_text ? fIsText : kDefaults), table_hint)
330 const string& key_col_name,
331 const string& num_col_name,
332 const string blob_column[],
335 m_TableName(
table_name), m_KeyColName(key_col_name),
336 m_NumColName(num_col_name), m_TableHint(table_hint),
344 string init_val((
flags &
fIsText) != 0 ?
"' '" :
"0x0");
345 string data_names, data_values, updates;
350 data_names += delim + blob_column[
i];
351 data_values += delim + init_val;
352 updates +=
' ' + blob_column[
i] +
" = " + init_val +
',';
355 updates[updates.size() - 1] =
'\n';
360 m_sCMD +=
" USING (VALUES (" + data_values +
"))\n";
361 m_sCMD +=
" AS s (" + data_names +
")\n";
364 m_sCMD +=
" WHEN MATCHED THEN UPDATE SET" + updates;
366 m_sCMD +=
" WHEN NOT MATCHED THEN\n";
368 m_sCMD +=
", " + data_names +
")\n";
369 m_sCMD +=
" VALUES (@key, @n, " + data_values +
")";
376 m_sCMD +=
"IF @@ROWCOUNT = 0\n";
379 m_sCMD +=
" SELECT @key, @n, " + data_values +
"\n";
404 if (conn_impl !=
NULL
439 "No more rows preallocated for key "
466 if (conn_impl !=
NULL
475 clear_extras =
"DELETE " + table_and_hint;
477 clear_extras =
"UPDATE " + table_and_hint +
" SET";
479 clear_extras += (j ?
", " :
" ") +
m_DataColName[j] +
"=NULL";
482 clear_extras += (
" WHERE " +
m_KeyColName +
" = @key AND "
485 string s=
"update " + table_and_hint +
" set";
490 " = @n " + clear_extras;
527 CSimpleBlobStore::TFlags
flags)
530 m_BlobColumn(
NULL), m_NofBC(0)
550 string sql =
"SELECT * FROM " +
m_Table +
" WHERE 1=0";
551 unique_ptr<CDB_LangCmd> lcmd(con->
LangCmd(
sql));
560 while(lcmd->HasMoreResults()) {
572 for(
unsigned int j= 0; j <
n; j++) {
573 switch (
r->ItemDataType(j)) {
617 const string& keyColName,
618 const string& numColName,
619 const string* blobColNames,
656 string s(
"set TEXTSIZE ");
658 unique_ptr<CDB_LangCmd> lcmd(pConn->
LangCmd(s));
666 while(lcmd->HasMoreResults())
668 unique_ptr<CDB_Result>
r(lcmd->Result());
669 if(!
r.get())
continue;
676 if(status.
Value() != 0)
699 if ( !table_hint.
empty() ) {
702 if (conn_impl !=
NULL
720 string sql = (
"IF EXISTS(SELECT * FROM " +
m_Table +
" WHERE "
722 unique_ptr<CDB_LangCmd> lcmd(con->
LangCmd(
sql));
732 while(lcmd->HasMoreResults()) {
733 unique_ptr<CDB_Result>
r(lcmd->Result());
734 if(!
r.get())
continue;
754 unique_ptr<CDB_LangCmd> lcmd(con->
LangCmd(
sql));
779 lcmd->BindParam(
"@blob_id", &blob_key);
789 while(lcmd->HasMoreResults()) {
790 unique_ptr<CDB_Result>
r(lcmd->Result());
804 unique_ptr<CCompressionStreamProcessor> zProc;
816 return iStream.release();
836 unique_ptr<CSimpleBlobStore> sbs
839 sbs->SetKey(blob_id);
852 unique_ptr<CCompressionStreamProcessor> zProc;
864 return oStream.release();
901 CSimpleBlobStore::TFlags
flags)
910 const string& tableName,
911 const string& keyColName,
912 const string& numColName,
913 const string* blobColNames,
931 const string& tableName,
932 const string& keyColName,
933 const string& numColName,
934 const string* blobColNames,
936 CSimpleBlobStore::TFlags
flags,
942 SetTableDescr(tableName, keyColName, numColName, blobColNames, nofBC,
971 const string& server,
973 const string& passwd,
987 const string& server,
989 const string& passwd,
993 CSimpleBlobStore::TFlags
flags)
995 m_Cntxt(pCntxt), m_Server(server), m_User(user), m_Passwd(passwd),
CBZip2Compressor – bzip2 based compressor.
CBZip2Decompressor – bzip2 based decompressor.
IBlobDescriptorMaker * m_dMaker
bool Load(istream &s, ECompressMethod cm=eNone, size_t image_limit=0, bool log_it=false)
virtual ERW_Result PendingCount(size_t *count)
Return the number of bytes ready to be read from input device without blocking.
virtual ERW_Result Read(void *buf, size_t count, size_t *bytes_read=0)
Read as many as count bytes into a buffer pointed to by buf argument.
bool Dump(ostream &s, ECompressMethod cm=eNone)
void Delete(const string &blob_id)
virtual ~CBlobStoreBase()
void SetTextSizeServerSide(CDB_Connection *pConn, size_t textSize=2147483647)
virtual CDB_Connection * GetConn()=0
CBlobStoreBase(const string &table_name, ECompressMethod cm, size_t image_limit, bool log_it)
virtual bool ReleaseConn(CDB_Connection *)=0
void SetTableDescr(const string &tableName, const string &keyColName, const string &numColName, const string *blobColNames, unsigned nofBC, bool isText=false)
ostream * OpenForWrite(const string &blob_id, const CTempString &table_hint=kEmptyStr)
Obtain an output stream for a specific BLOB.
istream * OpenForRead(const string &blob_id, const CTempString &table_hint=kEmptyStr)
Obtain an input stream for a specific BLOB.
virtual void GenReadQuery(const CTempString &table_hint)
bool Exists(const string &blob_id)
CSimpleBlobStore::TFlags m_Flags
virtual ~CBlobStoreDynamic()
virtual bool ReleaseConn(CDB_Connection *)
I_DriverContext * m_Cntxt
CBlobStoreDynamic(I_DriverContext *pCntxt, const string &server, const string &user, const string &passwd, const string &table_name, ECompressMethod cm=eNone, size_t image_limit=IMAGE_LIMIT_16MB, CSimpleBlobStore::TFlags flags=CSimpleBlobStore::kDefaults)
virtual CDB_Connection * GetConn()
virtual CDB_Connection * GetConn()
virtual ~CBlobStoreStatic()
CBlobStoreStatic(CDB_Connection *pConn, const string &table_name, ECompressMethod cm=eNone, size_t image_limit=IMAGE_LIMIT_16MB, CSimpleBlobStore::TFlags flags=CSimpleBlobStore::kDefaults)
virtual ERW_Result Flush(void)
Flush pending data (if any) down to output device.
virtual ERW_Result Write(const void *buf, size_t count, size_t *bytes_written=0)
Write up to count bytes from the buffer pointed to by buf argument onto output device.
IBlobDescriptorMaker * m_dMaker
Note about the "buf_size" parameter for streams in this API.
@ fOwnReader
Own the underlying reader.
@ fOwnWriter
Own the underlying writer.
virtual I_BlobDescriptor & BlobDescriptor(void)
virtual bool Init(CDB_Connection *con)
virtual ~CSimpleBlobStore()
CDB_BlobDescriptor m_Desc
@ fIsText
(N)TEXT or (N)VARCHAR(MAX)
@ fLogBlobs
Enable server-side logging.
@ fPreallocated
Don't create rows or clean up excess rows.
CSimpleBlobStore(const string &table_name, const string &key_col_name, const string &num_col_name, const string blob_column[], TFlags flags=kDefaults, const CTempString &table_hint=kEmptyStr)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Writer-based output stream.
CZipCompressor – zlib based compressor.
CZipDecompressor – zlib based decompressor.
virtual bool Fini(void)=0
virtual I_BlobDescriptor & BlobDescriptor(void)=0
virtual bool Init(CDB_Connection *con)=0
CDBConnParams::EServerType GetServerType(void)
static const char table_name[]
@ eDelete
Do delete processor object.
#define DATABASE_DRIVER_ERROR(message, err_code)
#define CHECK_DRIVER_ERROR(failed, message, err_code)
virtual bool HandleIt(CDB_Exception *ex)
Handle the exceptions resulting from a native API call, one-by-one.
CDB_Connection * Connect(const string &srv_name, const string &user_name, const string &passwd, TConnectionMode mode, bool reusable=false, const string &pool_name=kEmptyStr)
Create new connection to specified server (or service) within this context.
virtual bool SetMaxBlobSize(size_t nof_bytes)=0
Set maximal size for BLOB data.
virtual EDB_ResType ResultType() const
Get type of the result.
virtual I_ConnectionExtra & GetExtraFeatures(void)
Get interface for extra features that could be implemented in the driver.
virtual CDB_Result * Result()
Get result set.
bool SetParam(const string &name, CDB_Object *value)
virtual int RowCount() const
Get the number of rows affected by the command.
bool BindParam(const string &name, CDB_Object *value)
virtual bool Send()
Send command to the server.
virtual bool SendData(I_BlobDescriptor &desc, CDB_Stream &lob, bool log_it=true)
Shortcut to send text and image to the server without using the "Send-data" command (SendDataCmd)
virtual int CurrentItemNo() const
Return current item number we can retrieve (0,1,...)
virtual void DumpResults()
Dump the results of the command If result processor is installed for this connection,...
virtual bool SkipItem()
Skip result item.
virtual CDB_LangCmd * LangCmd(const string &lang_query)
Make language command.
void SetColumnName(const string &name)
virtual size_t ReadItem(void *buffer, size_t buffer_size, bool *is_null=0)
Read a result item body (for BLOB columns, mostly).
void SetSearchConditions(const string &cond)
virtual unsigned int NofItems() const
Get # of items (columns) in the result.
virtual bool HasMoreResults() const
virtual bool Fetch()
Fetch next row.
virtual size_t Append(const void *buff, size_t nof_bytes)
virtual void Truncate(size_t nof_bytes=kMax_Int)
const string & AsString(void) const
virtual size_t Size() const
int32_t Int4
4-byte (32-bit) signed integer
ERW_Result
Result codes for I/O operations.
@ eRW_NotImplemented
Action / information is not available.
@ eRW_Eof
End of data, should be considered permanent.
@ eRW_Error
Unrecoverable error, no retry possible.
@ eRW_Success
Everything is okay, I/O completed.
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
Reader-writer based streams.