CUBRID Engine  latest
db_elo.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ident "$Id$"
20 
21 #include "config.h"
22 
23 #include <stdio.h>
24 #include <string.h>
25 #include <assert.h>
26 
27 #include "elo.h"
28 #include "error_manager.h"
29 #include "storage_common.h"
30 #include "object_primitive.h"
31 #include "db.h"
32 #include "elo.h"
33 #include "db_elo.h"
34 #include "dbtype.h"
35 
36 /*
37  * db_elo.c - DB_API for ELO layer
38  */
39 
40 /*
41  * db_create_fbo () - create a new fbo value
42  * return: NO_ERROR if successful, error code otherwise
43  * value(in): DB_VALUE
44  * type(in): one of DB_TYPE_BLOB, DB_TYPE_CLOB
45  */
46 int
48 {
49  DB_ELO elo;
50  int ret;
51 
52  CHECK_1ARG_ERROR (value);
53 
54  ret = elo_create (&elo);
55  if (ret == NO_ERROR)
56  {
57  ret = db_make_elo (value, type, &elo);
58  if (ret == NO_ERROR)
59  {
60  value->need_clear = true;
61  }
62  }
63 
64  return ret;
65 }
66 
67 /*
68  * db_elo_copy_structure () -
69  * return:
70  * src(in):
71  * dest(out):
72  */
73 int
74 db_elo_copy_structure (const DB_ELO * src, DB_ELO * dest)
75 {
76  CHECK_2ARGS_ERROR (src, dest);
77 
78  return elo_copy_structure (src, dest);
79 }
80 
81 /*
82  * db_elo_free_structure () -
83  * return:
84  * elo(in):
85  */
86 void
88 {
89  if (elo != NULL)
90  {
91  elo_free_structure (elo);
92  }
93 }
94 
95 /*
96  * db_elo_copy () -
97  * return:
98  * src(in):
99  * dest(out):
100  */
101 int
102 db_elo_copy (DB_ELO * src, DB_ELO * dest)
103 {
104  CHECK_2ARGS_ERROR (src, dest);
105 
106  return elo_copy (src, dest);
107 }
108 
109 /*
110  * db_elo_delete () -
111  * return:
112  * elo(in):
113  */
114 int
116 {
117  CHECK_1ARG_ERROR (elo);
118 
119  return elo_delete (elo, false);
120 }
121 
122 /*
123  * db_elo_size () -
124  * return:
125  * elo(in):
126  */
127 DB_BIGINT
129 {
130  CHECK_1ARG_ERROR (elo);
131 
132  return elo_size (elo);
133 }
134 
135 /*
136  * db_elo_read () -
137  *
138  * return: error code or NO_ERROR
139  * elo(in):
140  * pos(in):
141  * buf(out):
142  * count(in):
143  */
144 int
145 db_elo_read (const DB_ELO * elo, off_t pos, void *buf, size_t count, DB_BIGINT * read_bytes)
146 {
147  INT64 ret;
148 
149  if (elo == NULL || pos < 0 || buf == NULL)
150  {
153  }
154 
155  ret = elo_read (elo, pos, buf, count);
156  if (ret < 0)
157  {
158  return (int) ret;
159  }
160  if (read_bytes != NULL)
161  {
162  *read_bytes = ret;
163  }
164  return NO_ERROR;
165 }
166 
167 /*
168  * db_elo_write () -
169  *
170  * return:
171  * elo(in):
172  * pos(in):
173  * buf(in):
174  * count(in):
175  */
176 int
177 db_elo_write (DB_ELO * elo, off_t pos, const void *buf, size_t count, DB_BIGINT * written_bytes)
178 {
179  INT64 ret;
180 
181  if (elo == NULL || pos < 0 || buf == NULL || count == 0)
182  {
185  }
186 
187  ret = elo_write (elo, pos, buf, count);
188  if (ret < 0)
189  {
190  return (int) ret;
191  }
192  if (written_bytes != NULL)
193  {
194  *written_bytes = ret;
195  }
196  return NO_ERROR;
197 }
void db_elo_free_structure(DB_ELO *elo)
Definition: db_elo.c:87
int elo_create(DB_ELO *elo)
Definition: elo.c:83
#define NO_ERROR
Definition: error_code.h:46
int db_elo_write(DB_ELO *elo, off_t pos, const void *buf, size_t count, DB_BIGINT *written_bytes)
Definition: db_elo.c:177
#define CHECK_2ARGS_ERROR(obj1, obj2)
Definition: db.h:195
DB_TYPE
Definition: dbtype_def.h:670
int db_create_fbo(DB_VALUE *value, DB_TYPE type)
Definition: db_elo.c:47
int db_elo_copy(DB_ELO *src, DB_ELO *dest)
Definition: db_elo.c:102
int db_make_elo(DB_VALUE *value, DB_TYPE type, const DB_ELO *elo)
int db_elo_delete(DB_ELO *elo)
Definition: db_elo.c:115
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
DB_BIGINT db_elo_size(DB_ELO *elo)
Definition: db_elo.c:128
#define CHECK_1ARG_ERROR(obj)
Definition: db.h:186
int elo_delete(DB_ELO *elo, bool force_delete)
Definition: elo.c:357
#define NULL
Definition: freelistheap.h:34
int db_elo_copy_structure(const DB_ELO *src, DB_ELO *dest)
Definition: db_elo.c:74
ssize_t elo_read(const DB_ELO *elo, off_t pos, void *buf, size_t count)
Definition: elo.c:453
need_clear_type need_clear
Definition: dbtype_def.h:1084
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
int64_t DB_BIGINT
Definition: dbtype_def.h:751
#define ARG_FILE_LINE
Definition: error_manager.h:44
off_t elo_size(DB_ELO *elo)
Definition: elo.c:421
ssize_t elo_write(DB_ELO *elo, off_t pos, const void *buf, size_t count)
Definition: elo.c:479
void elo_free_structure(DB_ELO *elo)
Definition: elo.c:186
#define ER_OBJ_INVALID_ARGUMENTS
Definition: error_code.h:275
int db_elo_read(const DB_ELO *elo, off_t pos, void *buf, size_t count, DB_BIGINT *read_bytes)
Definition: db_elo.c:145
int elo_copy_structure(const DB_ELO *elo, DB_ELO *dest)
Definition: elo.c:142
int elo_copy(DB_ELO *elo, DB_ELO *dest)
Definition: elo.c:211