|
10 | 10 | """ |
11 | 11 | Python wrapper around pxlib. |
12 | 12 |
|
13 | | -This module, written in Pyrex_, allow to read data from Paradox tables |
| 13 | +This module, written in Cython_, allow to read data from Paradox tables |
14 | 14 | using the pxlib_ library. |
15 | 15 |
|
16 | | -.. _pyrex: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ |
| 16 | +.. _cython: http://pxlib.sourceforge.net/ |
17 | 17 | .. _pxlib: http://pxlib.sourceforge.net/ |
18 | 18 | """ |
19 | 19 |
|
20 | 20 | import datetime |
21 | 21 |
|
22 | 22 | import sys |
23 | 23 |
|
24 | | -cdef extern from *: |
25 | | - ctypedef char* const_char_ptr "const char*" |
26 | | - |
| 24 | +cimport python_unicode |
27 | 25 | from cpython.mem cimport PyMem_Malloc, PyMem_Free |
28 | 26 | from cpython.version cimport PY_MAJOR_VERSION |
29 | 27 |
|
30 | 28 | from libc.stdlib cimport * |
31 | | -cdef extern from "stdlib.h" nogil: |
32 | | - void *memset(void *str, int c, size_t n) |
33 | | - void *memcpy(void *str1, void *str2, size_t n) |
34 | | - |
35 | | -cdef extern from "Python.h": |
36 | | - object PyString_FromStringAndSize(char *s, int len) |
37 | | - object PyString_Decode(char *s, int len, char *encoding, char *errors) |
38 | | - object PyString_FromStringAndSize(char *v, int len) |
39 | | - object PyString_AsDecodedObject(object str, char *encoding, char *errors) |
40 | | - |
41 | | - |
42 | | -cdef extern from "string.h": |
43 | | - int strnlen(char *s, int maxlen) |
44 | | - char *strcpy(char *, char *) |
45 | | - |
46 | | - |
47 | | -cdef extern from "paradox.h": |
48 | | - ctypedef enum fieldtype_t: |
49 | | - pxfAlpha = 0x01 |
50 | | - pxfDate = 0x02 |
51 | | - pxfShort = 0x03 |
52 | | - pxfLong = 0x04 |
53 | | - pxfCurrency = 0x05 |
54 | | - pxfNumber = 0x06 |
55 | | - pxfLogical = 0x09 |
56 | | - pxfMemoBLOb = 0x0C |
57 | | - pxfBLOb = 0x0D |
58 | | - pxfFmtMemoBLOb = 0x0E |
59 | | - pxfOLE = 0x0F |
60 | | - pxfGraphic = 0x10 |
61 | | - pxfTime = 0x14 |
62 | | - pxfTimestamp = 0x15 |
63 | | - pxfAutoInc = 0x16 |
64 | | - pxfBCD = 0x17 |
65 | | - pxfBytes = 0x18 |
66 | | - pxfNumTypes = 0x18 |
67 | | - |
68 | | - ctypedef enum filetype_t: |
69 | | - pxfFileTypIndexDB = 0 |
70 | | - pxfFileTypPrimIndex = 1 |
71 | | - pxfFileTypNonIndexDB = 2 |
72 | | - pxfFileTypNonIncSecIndex = 3 |
73 | | - pxfFileTypSecIndex = 4 |
74 | | - pxfFileTypIncSecIndex = 5 |
75 | | - pxfFileTypNonIncSecIndexG = 6 |
76 | | - pxfFileTypSecIndexG = 7 |
77 | | - pxfFileTypIncSecIndexG = 8 |
78 | | - |
79 | | - ctypedef struct pxfield_t: |
80 | | - char *px_fname |
81 | | - char px_ftype |
82 | | - int px_flen |
83 | | - int px_fdc |
84 | | - |
85 | | - ctypedef struct pxhead_t: |
86 | | - char *px_tablename |
87 | | - int px_recordsize |
88 | | - char px_filetype |
89 | | - int px_fileversion |
90 | | - int px_numrecords |
91 | | - int px_theonumrecords |
92 | | - int px_numfields |
93 | | - int px_maxtablesize |
94 | | - int px_headersize |
95 | | - int px_fileblocks |
96 | | - int px_firstblock |
97 | | - int px_lastblock |
98 | | - int px_indexfieldnumber |
99 | | - int px_indexroot |
100 | | - int px_numindexlevels |
101 | | - int px_writeprotected |
102 | | - int px_doscodepage |
103 | | - int px_primarykeyfields |
104 | | - char px_modifiedflags1 |
105 | | - char px_modifiedflags2 |
106 | | - char px_sortorder |
107 | | - int px_autoinc |
108 | | - int px_fileupdatetime |
109 | | - char px_refintegrity |
110 | | - pxfield_t *px_fields |
111 | | - |
112 | | - ctypedef struct pxdoc_t: |
113 | | - char *px_name |
114 | | - pxhead_t *px_head |
115 | | - char *targetencoding |
116 | | - void *(*malloc)(pxdoc_t *p, unsigned int size, char *caller) |
117 | | - void (*free)(pxdoc_t *p, void *mem) |
118 | | - |
119 | | - ctypedef struct pxdatablockinfo_t |
120 | | - ctypedef struct pxblob_t: |
121 | | - char *px_name |
122 | | - pxdoc_t * pxdoc |
123 | | - |
124 | | - ctypedef struct pxpindex_t |
125 | | - ctypedef struct pxstream_t |
126 | | - |
127 | | - |
128 | | - ctypedef struct Pxval_str: |
129 | | - char *val |
130 | | - int len |
131 | | - ctypedef union Pxval_value: |
132 | | - long lval |
133 | | - double dval |
134 | | - Pxval_str str |
135 | | - ctypedef struct pxval_t: |
136 | | - char isnull |
137 | | - int type |
138 | | - Pxval_value value |
139 | | - |
140 | | - |
141 | | - pxdoc_t *PX_new() |
142 | | - pxdoc_t* PX_new2(void (*errorhandler)(pxdoc_t *p, int type, const_char_ptr msg, void *data), |
143 | | - void* (*allocproc)(pxdoc_t *p, size_t size, const_char_ptr caller), |
144 | | - void* (*reallocproc)(pxdoc_t *p, void *mem, size_t size, const_char_ptr caller), |
145 | | - void (*freeproc)(pxdoc_t *p, void *mem)) |
146 | | - char *PX_strdup(pxdoc_t *pxdoc, char *str) |
147 | | - int PX_open_file(pxdoc_t *pxdoc, const_char_ptr filename) |
148 | | - int PX_create_file(pxdoc_t *pxdoc, pxfield_t *px_fields, unsigned int numfields, char *filename, int type) |
149 | | - int PX_read_primary_index(pxdoc_t *pindex) |
150 | | - int PX_add_primary_index(pxdoc_t *pxdoc, pxdoc_t *pindex) |
151 | | - int PX_set_targetencoding(pxdoc_t *pxdoc, char *encoding) |
152 | | - int PX_set_inputencoding(pxdoc_t *pxdoc, char *encoding) |
153 | | - int PX_set_parameter(pxdoc_t *pxdoc, char *name, char *value) |
154 | | - int PX_set_value(pxdoc_t *pxdoc, char *name, float value) |
155 | | - pxblob_t *PX_new_blob(pxdoc_t *pxdoc) |
156 | | - int PX_open_blob_file(pxblob_t *pxdoc, char *filename) |
157 | | - int PX_close(pxdoc_t *pxdoc) |
158 | | - int PX_close_blob(pxblob_t *pxdoc) |
159 | | - void *PX_get_record(pxdoc_t *pxdoc, int recno, void *data) |
160 | | - void *PX_get_record2(pxdoc_t *pxdoc, int recno, void *data, int *deleted, pxdatablockinfo_t *pxdbinfo) |
161 | | - int PX_get_data_alpha(pxdoc_t *pxdoc, void *data, int len, char **value) |
162 | | - int PX_get_data_bytes(pxdoc_t *pxdoc, void *data, int len, char **value) |
163 | | - int PX_get_data_double(pxdoc_t *pxdoc, void *data, int len, double *value) |
164 | | - int PX_get_data_long(pxdoc_t *pxdoc, void *data, int len, long *value) |
165 | | - int PX_get_data_short(pxdoc_t *pxdoc, void *data, int len, short int *value) |
166 | | - int PX_get_data_byte(pxdoc_t *pxdoc, void *data, int len, char *value) |
167 | | - |
168 | | - int PX_put_record(pxdoc_t *pxdoc, char *data) |
169 | | - |
170 | | - void PX_put_data_alpha(pxdoc_t *pxdoc, char *data, int len, char *value) |
171 | | - void PX_put_data_double(pxdoc_t *pxdoc, char *data, int len, double value) |
172 | | - void PX_put_data_long(pxdoc_t *pxdoc, char *data, int len, int value) |
173 | | - void PX_put_data_short(pxdoc_t *pxdoc, char *data, int len, short int value) |
174 | | - |
175 | | - char *PX_read_blobdata(pxblob_t *pxblob, void *data, int len, int *mod, int *blobsize) |
176 | | - void PX_SdnToGregorian(long int sdn, int *pYear, int *pMonth, int *pDay) |
177 | | - long int PX_GregorianToSdn(int year, int month, int day) |
| 29 | + |
| 30 | +from paradox cimport * |
178 | 31 |
|
179 | 32 | cdef void errorhandler(pxdoc_t *p, int type, char *msg, void *data): |
180 | 33 | print 'error', type, msg |
@@ -227,6 +80,9 @@ cdef class PXDoc: |
227 | 80 | def setParameter(self, parameter, value): |
228 | 81 | PX_set_parameter(self.doc, parameter, value) |
229 | 82 |
|
| 83 | + def getTableName(self): |
| 84 | + return self.doc.px_head.px_tablename |
| 85 | + |
230 | 86 | def __dealloc__(self): |
231 | 87 | """ |
232 | 88 | Close the data file |
|
0 commit comments