~mordred/ndb-bindings/resultsets

« back to all changes in this revision

Viewing changes to simple/main-rename.i

  • Committer: Monty Taylor
  • Date: 2007-02-22 18:56:15 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: monty@inaugust.com-20070222185615-p6hlt70ju1boapgh
Added the rest of the sample files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: c++ -*- 
 
2
/*  ndb-connectors: Wrappers for the NDBAPI
 
3
    Copyright (C) 2006 MySQL, Inc.
 
4
    
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or 
 
8
    (at your option) any later version.
 
9
    
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
*/
 
19
 
 
20
%include "typemaps.i"
 
21
 
 
22
%{
 
23
#include <NdbApi.hpp> 
 
24
%}
 
25
 
 
26
%include "ndb_constants.h"
 
27
%include "ndb_init.h"
 
28
 
 
29
 
 
30
#if defined(SWIG_PYTHON)
 
31
%init %{
 
32
ndb_init();
 
33
%}
 
34
#endif
 
35
 
 
36
enum AbortOption {
 
37
  CommitIfFailFree = 0,         
 
38
  TryCommit = 0,
 
39
  AbortOnError = 0,
 
40
  CommitAsMuchAsPossible = 2,
 
41
  AO_IgnoreError = 2
 
42
};
 
43
 
 
44
enum ExecType { 
 
45
  NoExecTypeDef = -1,
 
46
  Prepare,
 
47
  NoCommit,
 
48
  Commit,
 
49
  Rollback
 
50
};
 
51
 
 
52
typedef unsigned long long Uint64; 
 
53
typedef unsigned int Uint32; 
 
54
typedef signed long long Int64; 
 
55
typedef signed int Int32;
 
56
 
 
57
 
 
58
/*%include "cluster.hpp"*/
 
59
 
 
60
class Ndb_cluster_connection {
 
61
 
 
62
public:
 
63
 
 
64
  Ndb_cluster_connection(const char * connectstring = 0);
 
65
  ~Ndb_cluster_connection();
 
66
 
 
67
  %exception connect { 
 
68
    $action
 
69
      if (result) { 
 
70
        const char * msg = "Connect to management server failed"; 
 
71
#if defined(SWIGPYTHON)
 
72
        PyErr_SetString(PyExc_RuntimeError, msg); 
 
73
        return PyInt_FromLong(-1); 
 
74
#endif
 
75
#if defined(SWIGJAVA)
 
76
        jclass clazz = jenv->FindClass("java/lang/RuntimeException");
 
77
        jenv->ThrowNew(clazz, msg); 
 
78
        return -1; 
 
79
#endif 
 
80
      }
 
81
  }
 
82
 
 
83
  int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
 
84
  int wait_until_ready(int timeout_for_first_alive,
 
85
                       int timeout_after_first_alive);
 
86
};
 
87
 
 
88
 
 
89
%extend Ndb_cluster_connection {
 
90
public:
 
91
  Ndb* getNdb(const char* aCatalogName="", const char* aSchemaName="def") {
 
92
    Ndb* myNdb = new Ndb(self,aCatalogName,aSchemaName);
 
93
    return myNdb; 
 
94
  }
 
95
}
 
96
 
 
97
class Ndb { 
 
98
 
 
99
public:
 
100
  Ndb(Ndb_cluster_connection *ndb_cluster_connection,
 
101
      const char* aCatalogName = "", const char* aSchemaName = "def");
 
102
  ~Ndb();
 
103
 
 
104
 
 
105
 
 
106
  int init(int maxNoOfTransactions = 4);
 
107
 
 
108
  // Deprcated 
 
109
  int waitUntilReady(int timeout = 60);
 
110
  const NdbError & getNdbError() const;
 
111
 
 
112
  %exception startTransaction { 
 
113
    $action
 
114
      if (result==NULL) { 
 
115
        NdbError err = arg1->getNdbError();
 
116
        
 
117
        PyErr_SetString(PyExc_RuntimeError, err.message);
 
118
        return NULL; 
 
119
      }
 
120
  }
 
121
  NdbTransaction* startTransaction(const NdbDictionary::Table *table= 0,
 
122
                                   const char  *keyData = 0, 
 
123
                                   Uint32       keyLen = 0);
 
124
public:
 
125
  int getAutoIncrementValue(const char* aTableName, 
 
126
                            Uint64 & tupleId, Uint32 cacheSize);
 
127
  void closeTransaction(NdbTransaction*);
 
128
};     
 
129
 
 
130
%extend Ndb {
 
131
public:
 
132
  NdbTransaction* startTransaction(const char* aTableName, 
 
133
                                   const char *keyData) {
 
134
    const NdbDictionary::Dictionary *myDict = self->getDictionary();
 
135
    const NdbDictionary::Table *myTable = myDict->getTable(aTableName);
 
136
    return self->startTransaction(myTable,keyData);
 
137
  }
 
138
  NdbTransaction* startTransaction(const char* aTableName, 
 
139
                                   int keyData) {
 
140
    const NdbDictionary::Dictionary *myDict = self->getDictionary();
 
141
    const NdbDictionary::Table *myTable = myDict->getTable(aTableName);
 
142
    return self->startTransaction(myTable,(const char *) &keyData);
 
143
  }
 
144
 
 
145
  Uint64 getAutoIncrementValue(const char* aTableName,
 
146
                               Uint32 cacheSize) {
 
147
    
 
148
    Uint64 id = 0;
 
149
    self->getAutoIncrementValue(aTableName,id,cacheSize);
 
150
    return id;
 
151
  };
 
152
};
 
153
 
 
154
class NdbTransaction {
 
155
  ~NdbTransaction();
 
156
  NdbTransaction(Ndb* aNdb); 
 
157
 
 
158
public: 
 
159
  NdbOperation* getNdbOperation(const char* aTableName);
 
160
  NdbScanOperation* getNdbScanOperation(const char* aTableName);
 
161
  const NdbError & getNdbError() const;
 
162
  int execute(ExecType execType,
 
163
              AbortOption abortOption = AbortOnError,
 
164
              int force = 0 );
 
165
};
 
166
 
 
167
class NdbOperation {
 
168
 
 
169
 
 
170
  friend class Ndb;
 
171
  friend class NdbTransaction;
 
172
  friend class NdbScanOperation;
 
173
  friend class NdbScanReceiver;
 
174
  friend class NdbScanFilter;
 
175
  friend class NdbScanFilterImpl;
 
176
  friend class NdbReceiver;
 
177
  friend class NdbBlob;
 
178
 
 
179
public:
 
180
 
 
181
  enum Type {
 
182
    PrimaryKeyAccess = 0,
 
183
    UniqueIndexAccess = 1,
 
184
    TableScan = 2,
 
185
    OrderedIndexScan = 3, 
 
186
    };
 
187
 
 
188
  enum LockMode {
 
189
    LM_Read = 0,
 
190
    LM_Exclusive = 1,
 
191
    LM_CommittedRead = 2,
 
192
    LM_Dirty = 2
 
193
  };
 
194
 
 
195
 
 
196
 
 
197
#if defined(SWIGPYTHON)
 
198
 
 
199
  %rename(setValueU) setValue(const char *, Uint32);
 
200
  %rename(setValueU64) setValue(const char *, Uint64);
 
201
 
 
202
  %rename(setVal)  setValue(const char* anAttrName, const char* aValue);
 
203
  %rename(setVal)  setValue(const char* anAttrName, Int32 aValue);
 
204
  %rename(setVal)  setValue(const char* anAttrName, Uint32 aValue);
 
205
  %rename(setVal)  setValue(const char* anAttrName, Uint64 aValue);
 
206
  %rename(setVal)  setValue(const char* anAttrName, Int64 aValue);
 
207
  %rename(setVal)  setValue(const char* anAttrName, float aValue);
 
208
  %rename(setVal)  setValue(const char* anAttrName, double aValue);
 
209
  %rename(setVal)  setValue(Uint32 anAttrId, const char* aValue);
 
210
  %rename(setVal)  setValue(Uint32 anAttrId, Int32 aValue);
 
211
  %rename(setVal)  setValue(Uint32 anAttrId, Uint32 aValue);
 
212
  %rename(setVal)  setValue(Uint32 anAttrId, Int64 aValue);
 
213
  %rename(setVal)  setValue(Uint32 anAttrId, Uint64 aValue);
 
214
  %rename(setVal)  setValue(Uint32 anAttrId, float aValue);
 
215
  %rename(setVal)  setValue(Uint32 anAttrId, double aValue);
 
216
 
 
217
 
 
218
#endif
 
219
 
 
220
  int  setValue(const char* anAttrName, const char* aValue);
 
221
  int  setValue(const char* anAttrName, Int32 aValue);
 
222
  int  setValue(const char* anAttrName, Uint32 aValue);
 
223
  int  setValue(const char* anAttrName, Uint64 aValue);
 
224
  int  setValue(const char* anAttrName, Int64 aValue);
 
225
  int  setValue(const char* anAttrName, float aValue);
 
226
  int  setValue(const char* anAttrName, double aValue);
 
227
  int  setValue(Uint32 anAttrId, const char* aValue);
 
228
  int  setValue(Uint32 anAttrId, Int32 aValue);
 
229
  int  setValue(Uint32 anAttrId, Uint32 aValue);
 
230
  int  setValue(Uint32 anAttrId, Int64 aValue);
 
231
  int  setValue(Uint32 anAttrId, Uint64 aValue);
 
232
  int  setValue(Uint32 anAttrId, float aValue);
 
233
  int  setValue(Uint32 anAttrId, double aValue);
 
234
 
 
235
 
 
236
  const NdbError & getNdbError() const;
 
237
 
 
238
  
 
239
  virtual int insertTuple();
 
240
 
 
241
#if defined(SWIGPYTHON)
 
242
  %rename(equalU) equal(const char*, Uint32);
 
243
  %rename(equalU64) equal(const char*, Uint64);
 
244
  %rename(equalU) equal(Uint32, Uint32);
 
245
  %rename(equalU64) equal(Uint32, Uint64);
 
246
#endif
 
247
 
 
248
 
 
249
  int  equal(const char* anAttrName, const char* aValue);
 
250
  int  equal(const char* anAttrName, Uint32 aValue);    
 
251
  int  equal(const char* anAttrName, Int32 aValue);     
 
252
  int  equal(const char* anAttrName, Int64 aValue);     
 
253
  int  equal(const char* anAttrName, Uint64 aValue);
 
254
  int  equal(Uint32 anAttrId, const char* aValue);
 
255
  int  equal(Uint32 anAttrId, Int32 aValue);    
 
256
  int  equal(Uint32 anAttrId, Uint32 aValue);   
 
257
  int  equal(Uint32 anAttrId, Int64 aValue);    
 
258
  int  equal(Uint32 anAttrId, Uint64 aValue);
 
259
 
 
260
 
 
261
protected:
 
262
  NdbOperation(Ndb* aNdb, Type aType = PrimaryKeyAccess);       
 
263
  virtual ~NdbOperation();
 
264
};
 
265
 
 
266
 
 
267
 
 
268
class NdbError {
 
269
  enum Status {
 
270
    Success = ndberror_st_success,
 
271
    TemporaryError = ndberror_st_temporary,
 
272
    PermanentError = ndberror_st_permanent,
 
273
    UnknownResult = ndberror_st_unknown
 
274
  };
 
275
  
 
276
  enum Classification {
 
277
    NoError = ndberror_cl_none,
 
278
    ApplicationError = ndberror_cl_application,
 
279
    NoDataFound = ndberror_cl_no_data_found,
 
280
    ConstraintViolation = ndberror_cl_constraint_violation,
 
281
    SchemaError = ndberror_cl_schema_error,
 
282
    UserDefinedError = ndberror_cl_user_defined,
 
283
    InsufficientSpace = ndberror_cl_insufficient_space,
 
284
    TemporaryResourceError = ndberror_cl_temporary_resource,
 
285
    NodeRecoveryError = ndberror_cl_node_recovery,
 
286
    OverloadError = ndberror_cl_overload,
 
287
    TimeoutExpired = ndberror_cl_timeout_expired,
 
288
    UnknownResultError = ndberror_cl_unknown_result,
 
289
    InternalError = ndberror_cl_internal_error,
 
290
    FunctionNotImplemented = ndberror_cl_function_not_implemented,
 
291
    UnknownErrorCode = ndberror_cl_unknown_error_code,
 
292
    NodeShutdown = ndberror_cl_node_shutdown,
 
293
    SchemaObjectExists = ndberror_cl_schema_object_already_exists,
 
294
    InternalTemporary = ndberror_cl_internal_temporary
 
295
  };
 
296
  
 
297
  Status status;
 
298
  Classification classification;
 
299
  int code;
 
300
  int mysql_code;
 
301
  const char * message;
 
302
  char * details;
 
303
 
 
304
 
 
305
  NdbError(){
 
306
    status = UnknownResult;
 
307
    classification = NoError;
 
308
    code = 0;
 
309
    mysql_code = 0;
 
310
    message = 0;
 
311
    details = 0;
 
312
  }
 
313
  NdbError(const ndberror_struct & ndberror){
 
314
    status = (NdbError::Status) ndberror.status;
 
315
    classification = (NdbError::Classification) ndberror.classification;
 
316
    code = ndberror.code;
 
317
    mysql_code = ndberror.mysql_code;
 
318
    message = ndberror.message;
 
319
    details = ndberror.details;
 
320
  }
 
321
  operator ndberror_struct() const {
 
322
    ndberror_struct ndberror;
 
323
    ndberror.status = (ndberror_status_enum) status;
 
324
    ndberror.classification = (ndberror_classification_enum) classification;
 
325
    ndberror.code = code;
 
326
    ndberror.mysql_code = mysql_code;
 
327
    ndberror.message = message;
 
328
    ndberror.details = details;
 
329
    return ndberror;
 
330
  }
 
331
 
 
332
};
 
333
%extend NdbError { 
 
334
  const char * getMessage() { 
 
335
   return self->message; 
 
336
  }
 
337
}
 
338
/* test */
 
339
/* -*- mode: c++ -*- */