summaryrefslogtreecommitdiff
path: root/storage/ndb/src/old_files/newtonapi/dba_internal.hpp
blob: 84ae7ba222b27791c373703ddf320adac6a8423e (plain)
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
/* Copyright (C) 2003 MySQL AB

   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef DBA_INTERNAL_HPP
#define DBA_INTERNAL_HPP

#include <ndb_global.h>

extern "C" {
#include "dba.h"
}

#include <NdbApi.hpp>
#include <NdbMutex.h>
#include <NdbOut.hpp>

#ifndef INT_MAX
#define INT_MAX          2147483647
#endif

#ifdef DEBUG
#define DBA_DEBUG(x) ndbout << x << endl
#else
#define DBA_DEBUG(x)
#endif

extern Ndb      * DBA__TheNdb;
extern NdbMutex * DBA__TheNewtonMutex;

extern unsigned DBA__SentTransactions;
extern unsigned DBA__RecvTransactions;

/**
 * Configuration
 */
extern int DBA__NBP_Intervall;          // Param 0
extern int DBA__BulkReadCount;          // Param 1
extern int DBA__StartTransactionTimout; // Param 2
extern int DBA__NBP_Force;              // Param 3

/**
 * Error handling
 */
void DBA__SetLatestError(DBA_Error_t, DBA_ErrorCode_t, const char *, ...);

/**
 * Magic string
 *
 * Used to make sure that user passes correct pointers
 */
const int DBA__MagicLength = 4;
const char DBA__TheMagic[DBA__MagicLength] = { 'K', 'E', 'S', 'O' };

struct DBA_Binding {
  char magic[DBA__MagicLength];
  int  checkSum;
  
  char * tableName;
  int structSz;
  
  int noOfKeys;
  int *keyIds;
  int *keyOffsets;
  
  int noOfColumns;
  int *columnIds;
  int *columnOffsets;

  int noOfSubBindings;
  struct DBA_Binding **subBindings;
  int * subBindingOffsets;
  
  int data[1];
};

struct DBA__DataTypesMapping {
  DBA_DataTypes_t newtonType;
  NdbDictionary::Column::Type ndbType;
};

const DBA__DataTypesMapping DBA__DataTypesMappings[] = {
  { DBA_CHAR, NdbDictionary::Column::Char },
  { DBA_INT,  NdbDictionary::Column::Int }
};

const int DBA__NoOfMappings = sizeof(DBA__DataTypesMappings)/
                              sizeof(DBA__DataTypesMapping);

/**
 * Validate magic string and checksum of a binding
 */
bool DBA__ValidBinding(const DBA_Binding_t * bindings);
bool DBA__ValidBindings(const DBA_Binding_t * const * pBindings, int n);

/**
 * Recursive equalGetValue (used for read)
 *           equalSetValue (used for write)
 *           equal         (used for delete)
 */
bool DBA__EqualGetValue(NdbOperation *, const DBA_Binding_t *, void *);
bool DBA__EqualSetValue(NdbOperation *, const DBA_Binding_t *, const void *);
bool DBA__Equal        (NdbOperation *, const DBA_Binding_t *, const void *);

inline void require(bool test){
  if(!test)
    abort();
}

#endif