~ubuntu-branches/ubuntu/karmic/firebird2.1/karmic

« back to all changes in this revision

Viewing changes to src/common/classes/UserBlob.h

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2008-05-26 23:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20080526235925-2pnqj6nxpppoeaer
Tags: upstream-2.1.0.17798-0.ds2
ImportĀ upstreamĀ versionĀ 2.1.0.17798-0.ds2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  The contents of this file are subject to the Initial
 
3
 *  Developer's Public License Version 1.0 (the "License");
 
4
 *  you may not use this file except in compliance with the
 
5
 *  License. You may obtain a copy of the License at
 
6
 *  http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
 
7
 *
 
8
 *  Software distributed under the License is distributed AS IS,
 
9
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied.
 
10
 *  See the License for the specific language governing rights
 
11
 *  and limitations under the License.
 
12
 *
 
13
 *  The Original Code was created by Claudio Valderrama on 16-Mar-2007
 
14
 *  for the Firebird Open Source RDBMS project.
 
15
 *
 
16
 *  Copyright (c) 2007 Claudio Valderrama
 
17
 *  and all contributors signed below.
 
18
 *
 
19
 *  All Rights Reserved.
 
20
 *  Contributor(s): ______________________________________.
 
21
 *
 
22
 */
 
23
 
 
24
#ifndef FB_USER_BLOB_H
 
25
#define FB_USER_BLOB_H
 
26
 
 
27
#include "firebird.h"
 
28
#include <memory.h>
 
29
 
 
30
class UserBlob
 
31
{
 
32
public:
 
33
        explicit UserBlob(ISC_STATUS* status);
 
34
        ~UserBlob();
 
35
        bool open(FB_API_HANDLE& db, FB_API_HANDLE& trans, ISC_QUAD& blobid);
 
36
        bool open(FB_API_HANDLE& db, FB_API_HANDLE& trans, ISC_QUAD& blobid,
 
37
                                USHORT bpb_len, const UCHAR* bpb);
 
38
        bool create(FB_API_HANDLE& db, FB_API_HANDLE& trans, ISC_QUAD& blobid);
 
39
        bool create(FB_API_HANDLE& db, FB_API_HANDLE& trans, ISC_QUAD& blobid,
 
40
                                USHORT bpb_len, const UCHAR* bpb);
 
41
        bool close(bool force_internal_SV = false);
 
42
        bool getSegment(size_t len, void* buffer, size_t& real_len);
 
43
        bool getData(size_t len, void* buffer, size_t& real_len, bool use_sep, const UCHAR separator);
 
44
        bool putSegment(size_t len, const void* buffer);
 
45
        bool putSegment(size_t len, const void* buffer, size_t& real_len);
 
46
        bool putData(size_t len, const void* buffer, size_t& real_len);
 
47
        bool isOpen() const;
 
48
        ISC_STATUS getCode() const;
 
49
//      FB_API_HANDLE& getHandle();
 
50
        bool getInfo(size_t items_size, const UCHAR* blr_items, size_t info_size, UCHAR* blob_info) const;
 
51
        static bool blobIsNull(const ISC_QUAD& blobid);
 
52
private:
 
53
        enum b_direction
 
54
        {
 
55
                dir_none,
 
56
                dir_read,
 
57
                dir_write
 
58
        };
 
59
        ISC_STATUS* const m_status;
 
60
        FB_API_HANDLE m_blob;
 
61
        b_direction m_direction;
 
62
        ISC_STATUS_ARRAY m_default_status;
 
63
};
 
64
 
 
65
 
 
66
inline UserBlob::UserBlob(ISC_STATUS* status)
 
67
        : m_status(status ? status : m_default_status), m_blob(0), m_direction(dir_none)
 
68
{
 
69
        memset(m_default_status, 0, sizeof(m_default_status));
 
70
}
 
71
 
 
72
inline UserBlob::~UserBlob()
 
73
{
 
74
        close(true);
 
75
}
 
76
 
 
77
inline bool UserBlob::isOpen() const
 
78
{
 
79
        return m_blob != 0 && m_direction != dir_none;
 
80
}
 
81
 
 
82
// Do not call it after close(true) unless you did open() or create() again!!!
 
83
inline ISC_STATUS UserBlob::getCode() const
 
84
{
 
85
        return m_status[1];
 
86
}
 
87
 
 
88
//inline FB_API_HANDLE& UserBlob::getHandle()
 
89
//{
 
90
//      return m_blob;
 
91
//}
 
92
 
 
93
inline bool UserBlob::blobIsNull(const ISC_QUAD& blobid)
 
94
{
 
95
        return blobid.gds_quad_high == 0 && blobid.gds_quad_low == 0;
 
96
}
 
97
 
 
98
 
 
99
bool getBlobSize(       const UserBlob& b,
 
100
                                        SLONG* size,
 
101
                                        SLONG* seg_count,
 
102
                                        SLONG* max_seg);
 
103
 
 
104
 
 
105
#endif // FB_USER_BLOB_H
 
106