File: hk_paradoxdatasource.cpp

package info (click to toggle)
hk-classes 0.8.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,872 kB
  • ctags: 16,819
  • sloc: cpp: 90,990; ansic: 78,016; sh: 8,385; python: 3,793; makefile: 292
file content (191 lines) | stat: -rw-r--r-- 3,471 bytes parent folder | download | duplicates (2)
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
// ****************************************************************************
// copyright (c) 2000-2005 Horst Knorr <hk_classes@knoda.org>
// This file is part of the hk_paradoxclasses library.
// This file may be distributed and/or modified under the terms of the
// GNU Library Public License version 2 as published by the Free Software
// Foundation and appearing in the file COPYING included in the
// packaging of this file.
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// ****************************************************************************
#include "hk_paradoxdatasource.h"
#include "hk_paradoxdatabase.h"
#include "hk_paradoxconnection.h"
#include "hk_paradoxcolumn.h"
#include "hk_string.h"
#include <exception>
#include <new>

static hk_string errormsg;

void errorhandler(pxdoc_t *, int , const char *str, void *)
{
  cerr << "PXLib:"<<str<<endl;
  errormsg=str;
}

hk_string lasterror()
{
  return errormsg;
}

hk_paradoxdatasource::hk_paradoxdatasource(hk_paradoxdatabase* d,hk_presentation* p):hk_storagedatasource(d,p)
{
#ifdef HK_DEBUG
//wanna_debug(true);
    hkdebug("hk_paradoxdatasource::constructor");
#endif
    p_enabled=false;
    p_paradoxdatabase=d;
    p_paradoxhandle=NULL;//PX_new2(errorhandler,NULL,NULL,NULL);
    //p_paradoxhandle=PX_new();

    p_paradoxheader=NULL;
    p_true="1";
    p_false="0";
}


hk_paradoxdatasource::~hk_paradoxdatasource()
{
#ifdef HK_DEBUG
    hkdebug("hk_paradoxdatasource::destructor");
#endif
    if (accessmode()!=standard &&is_enabled()) driver_specific_batch_disable();
if ( p_paradoxhandle )
{
        PX_close(p_paradoxhandle);
       	PX_delete(p_paradoxhandle);
}

}





bool hk_paradoxdatasource::driver_specific_enable(void)
{
errormsg="";
     if (!datasource_open())
      {
       return false;
      }


        try
       {
        while (datasource_fetch_next_row())
	 {
	 }
       }
       catch (std::bad_alloc errormessage)
       {
         return true;
       }

      //dump_data();
      datasource_close();

return true;
}

hk_column* hk_paradoxdatasource::driver_specific_new_column(void)
{
#ifdef HK_DEBUG
    hkdebug("hk_paradoxdatasource::driver_specific_new_column");
#endif
    hk_column* col=new hk_paradoxcolumn(this,p_true,p_false);

    return col;
}











list<hk_column*>* hk_paradoxdatasource::driver_specific_columns(void)
{

return p_columns;
}



bool hk_paradoxdatasource::driver_specific_create_columns(void)
{
  clear_columnlist();
  p_columns=new list<hk_column*>;

return true;
}




bool hk_paradoxdatasource::driver_specific_batch_enable(void)
{
if (!datasource_open()) return false;
if (accessmode()==batchwrite)   return true;
p_counter=0;
if (datasource_fetch_next_row())
  set_maxrows(1);
else set_maxrows(0);
return true;
}


bool hk_paradoxdatasource::driver_specific_batch_disable(void)
{
return datasource_close();

}


bool hk_paradoxdatasource::driver_specific_batch_goto_next(void)
{
try
{
if (datasource_fetch_next_row())
  {
    set_maxrows(max_rows()+1);
    ++p_counter;
    return true;
  }
 else
    return false;
}
catch (std::bad_alloc errormessage)
 {
  datasource_close();
  return false;
 }
}


bool hk_paradoxdatasource::datasource_open(void)
{
 return true;
}

bool hk_paradoxdatasource::datasource_fetch_next_row(void)
{

 return true;
}


bool hk_paradoxdatasource::datasource_close(void)
{
 return true;
}