~mordred/ndb-bindings/resultsets

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// -*- mode: c++ -*- 
/*  ndb-bindings: Bindings for the NDB API
    Copyright (C) 2006 MySQL, Inc.
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or 
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

%include "typemaps.i"

%{
#include <NdbApi.hpp> 
%}

%include "ndb_constants.h"
%include "ndb_init.h"


#if defined(SWIG_PYTHON)
%init %{
ndb_init();
%}
#endif

enum AbortOption {
  CommitIfFailFree = 0,         
  TryCommit = 0,
  AbortOnError = 0,
  CommitAsMuchAsPossible = 2,
  AO_IgnoreError = 2
};

enum ExecType { 
  NoExecTypeDef = -1,
  Prepare,
  NoCommit,
  Commit,
  Rollback
};

typedef unsigned long long Uint64; 
typedef unsigned int Uint32; 
typedef signed long long Int64; 
typedef signed int Int32;


/*%include "cluster.hpp"*/

class Ndb_cluster_connection {

public:

  Ndb_cluster_connection(const char * connectstring = 0);
  ~Ndb_cluster_connection();

  %exception connect { 
    $action
      if (result) { 
	const char * msg = "Connect to management server failed"; 
#if defined(SWIGPYTHON)
        PyErr_SetString(PyExc_RuntimeError, msg); 
        return PyInt_FromLong(-1); 
#endif
#if defined(SWIGJAVA)
	jclass clazz = jenv->FindClass("java/lang/RuntimeException");
	jenv->ThrowNew(clazz, msg); 
        return -1; 
#endif 
      }
  }

  int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
  int wait_until_ready(int timeout_for_first_alive,
		       int timeout_after_first_alive);
};


%extend Ndb_cluster_connection {
public:
  Ndb* getNdb(const char* aCatalogName="", const char* aSchemaName="def") {
    Ndb* myNdb = new Ndb(self,aCatalogName,aSchemaName);
    return myNdb; 
  }
}

class Ndb { 

public:
  Ndb(Ndb_cluster_connection *ndb_cluster_connection,
      const char* aCatalogName = "", const char* aSchemaName = "def");
  ~Ndb();



  int init(int maxNoOfTransactions = 4);

  // Deprcated 
  int waitUntilReady(int timeout = 60);
  const NdbError & getNdbError() const;

  %exception startTransaction { 
    $action
      if (result==NULL) { 
        NdbError err = arg1->getNdbError();
	
        PyErr_SetString(PyExc_RuntimeError, err.message);
        return NULL; 
      }
  }
  NdbTransaction* startTransaction(const NdbDictionary::Table *table= 0,
				   const char  *keyData = 0, 
				   Uint32       keyLen = 0);
public:
  int getAutoIncrementValue(const char* aTableName, 
                            Uint64 & tupleId, Uint32 cacheSize);
  void closeTransaction(NdbTransaction*);
};     

%extend Ndb {
public:
  NdbTransaction* startTransaction(const char* aTableName, 
				   const char *keyData) {
    const NdbDictionary::Dictionary *myDict = self->getDictionary();
    const NdbDictionary::Table *myTable = myDict->getTable(aTableName);
    return self->startTransaction(myTable,keyData);
  }
  NdbTransaction* startTransaction(const char* aTableName, 
				   int keyData) {
    const NdbDictionary::Dictionary *myDict = self->getDictionary();
    const NdbDictionary::Table *myTable = myDict->getTable(aTableName);
    return self->startTransaction(myTable,(const char *) &keyData);
  }

  Uint64 getAutoIncrementValue(const char* aTableName,
			       Uint32 cacheSize) {
    
    Uint64 id = 0;
    self->getAutoIncrementValue(aTableName,id,cacheSize);
    return id;
  };
};

class NdbTransaction {
  ~NdbTransaction();
  NdbTransaction(Ndb* aNdb); 

public: 
  NdbOperation* getNdbOperation(const char* aTableName);
  NdbScanOperation* getNdbScanOperation(const char* aTableName);
  const NdbError & getNdbError() const;
  int execute(ExecType execType,
	      AbortOption abortOption = AbortOnError,
	      int force = 0 );
};

class NdbOperation {


  friend class Ndb;
  friend class NdbTransaction;
  friend class NdbScanOperation;
  friend class NdbScanReceiver;
  friend class NdbScanFilter;
  friend class NdbScanFilterImpl;
  friend class NdbReceiver;
  friend class NdbBlob;

public:

  enum Type {
    PrimaryKeyAccess = 0,
    UniqueIndexAccess = 1,
    TableScan = 2,
    OrderedIndexScan = 3, 
    };

  enum LockMode {
    LM_Read = 0,
    LM_Exclusive = 1,
    LM_CommittedRead = 2,
    LM_Dirty = 2
  };



#if defined(SWIGPYTHON)

  %rename(setValueU) setValue(const char *, Uint32);
  %rename(setValueU64) setValue(const char *, Uint64);

  %rename(setVal)  setValue(const char* anAttrName, const char* aValue);
  %rename(setVal)  setValue(const char* anAttrName, Int32 aValue);
  %rename(setVal)  setValue(const char* anAttrName, Uint32 aValue);
  %rename(setVal)  setValue(const char* anAttrName, Uint64 aValue);
  %rename(setVal)  setValue(const char* anAttrName, Int64 aValue);
  %rename(setVal)  setValue(const char* anAttrName, float aValue);
  %rename(setVal)  setValue(const char* anAttrName, double aValue);
  %rename(setVal)  setValue(Uint32 anAttrId, const char* aValue);
  %rename(setVal)  setValue(Uint32 anAttrId, Int32 aValue);
  %rename(setVal)  setValue(Uint32 anAttrId, Uint32 aValue);
  %rename(setVal)  setValue(Uint32 anAttrId, Int64 aValue);
  %rename(setVal)  setValue(Uint32 anAttrId, Uint64 aValue);
  %rename(setVal)  setValue(Uint32 anAttrId, float aValue);
  %rename(setVal)  setValue(Uint32 anAttrId, double aValue);


#endif

  int  setValue(const char* anAttrName, const char* aValue);
  int  setValue(const char* anAttrName, Int32 aValue);
  int  setValue(const char* anAttrName, Uint32 aValue);
  int  setValue(const char* anAttrName, Uint64 aValue);
  int  setValue(const char* anAttrName, Int64 aValue);
  int  setValue(const char* anAttrName, float aValue);
  int  setValue(const char* anAttrName, double aValue);
  int  setValue(Uint32 anAttrId, const char* aValue);
  int  setValue(Uint32 anAttrId, Int32 aValue);
  int  setValue(Uint32 anAttrId, Uint32 aValue);
  int  setValue(Uint32 anAttrId, Int64 aValue);
  int  setValue(Uint32 anAttrId, Uint64 aValue);
  int  setValue(Uint32 anAttrId, float aValue);
  int  setValue(Uint32 anAttrId, double aValue);


  const NdbError & getNdbError() const;

  
  virtual int insertTuple();

#if defined(SWIGPYTHON)
  %rename(equalU) equal(const char*, Uint32);
  %rename(equalU64) equal(const char*, Uint64);
  %rename(equalU) equal(Uint32, Uint32);
  %rename(equalU64) equal(Uint32, Uint64);
#endif


  int  equal(const char* anAttrName, const char* aValue);
  int  equal(const char* anAttrName, Uint32 aValue);	
  int  equal(const char* anAttrName, Int32 aValue);	
  int  equal(const char* anAttrName, Int64 aValue);	
  int  equal(const char* anAttrName, Uint64 aValue);
  int  equal(Uint32 anAttrId, const char* aValue);
  int  equal(Uint32 anAttrId, Int32 aValue);	
  int  equal(Uint32 anAttrId, Uint32 aValue);	
  int  equal(Uint32 anAttrId, Int64 aValue);	
  int  equal(Uint32 anAttrId, Uint64 aValue);


#if defined(SWIGPYTHON)
  %pythoncode %{
def setValue(self,name,value,length=None):
  if isinstance(value,"".__class__):
    value="%c%s" % (len(value),value)
  if length is None:
    return self.setVal(name,value)
  return self.setVal(name,value,length)
      %}
#endif


protected:
  NdbOperation(Ndb* aNdb, Type aType = PrimaryKeyAccess);	
  virtual ~NdbOperation();
};



class NdbError {
  enum Status {
    Success = ndberror_st_success,
    TemporaryError = ndberror_st_temporary,
    PermanentError = ndberror_st_permanent,
    UnknownResult = ndberror_st_unknown
  };
  
  enum Classification {
    NoError = ndberror_cl_none,
    ApplicationError = ndberror_cl_application,
    NoDataFound = ndberror_cl_no_data_found,
    ConstraintViolation = ndberror_cl_constraint_violation,
    SchemaError = ndberror_cl_schema_error,
    UserDefinedError = ndberror_cl_user_defined,
    InsufficientSpace = ndberror_cl_insufficient_space,
    TemporaryResourceError = ndberror_cl_temporary_resource,
    NodeRecoveryError = ndberror_cl_node_recovery,
    OverloadError = ndberror_cl_overload,
    TimeoutExpired = ndberror_cl_timeout_expired,
    UnknownResultError = ndberror_cl_unknown_result,
    InternalError = ndberror_cl_internal_error,
    FunctionNotImplemented = ndberror_cl_function_not_implemented,
    UnknownErrorCode = ndberror_cl_unknown_error_code,
    NodeShutdown = ndberror_cl_node_shutdown,
    SchemaObjectExists = ndberror_cl_schema_object_already_exists,
    InternalTemporary = ndberror_cl_internal_temporary
  };
  
  Status status;
  Classification classification;
  int code;
  int mysql_code;
  const char * message;
  char * details;


  NdbError(){
    status = UnknownResult;
    classification = NoError;
    code = 0;
    mysql_code = 0;
    message = 0;
    details = 0;
  }
  NdbError(const ndberror_struct & ndberror){
    status = (NdbError::Status) ndberror.status;
    classification = (NdbError::Classification) ndberror.classification;
    code = ndberror.code;
    mysql_code = ndberror.mysql_code;
    message = ndberror.message;
    details = ndberror.details;
  }
  operator ndberror_struct() const {
    ndberror_struct ndberror;
    ndberror.status = (ndberror_status_enum) status;
    ndberror.classification = (ndberror_classification_enum) classification;
    ndberror.code = code;
    ndberror.mysql_code = mysql_code;
    ndberror.message = message;
    ndberror.details = details;
    return ndberror;
  }

};

%extend NdbError { 
  const char * getMessage() { 
   return self->message; 
  }
}
/* test */
/* -*- mode: c++ -*- */