You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

424 lines
13 KiB

1) Handling string memory allocation with a new STRING class. This is only the beginning. Defining the STRING class and begining to use it (MYSQL) 2) Change the xtrace, use_tempfile and exact_info connect variables from GLOBAL to SESSION. Remaining GLOBAL variables have been made readonly. 3) Take care of LEX_STRING variables. The .str should not be regarded as allways being 0 terminated. This is handled by the Strz functions that make sure to return 0 terminated strings. Bug fix: - When inserting in MYSQL table with special column(s) a query such as: insert into t2 values(0,4,'new04'),(0,5,'new05'); failed saying: column id (the special column) not found in t2. It is now accepted but must be counted in values (these 0 are ignored) - ROWID was returning row numbers based 0. Now it is from base 1. modified: storage/connect/array.cpp storage/connect/blkfil.cpp storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamtxt.cpp storage/connect/filamvct.cpp storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/filter.cpp storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/libdoc.cpp storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/odbconn.cpp storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabdos.cpp storage/connect/tabfix.cpp storage/connect/tabfmt.cpp storage/connect/table.cpp storage/connect/tabmul.cpp storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/taboccur.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabsys.cpp storage/connect/tabtbl.cpp storage/connect/tabutil.cpp storage/connect/tabvct.cpp storage/connect/tabwmi.cpp storage/connect/tabwmi.h storage/connect/tabxcl.cpp storage/connect/tabxml.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/value.h storage/connect/xindex.cpp storage/connect/xobject.cpp storage/connect/xobject.h storage/connect/xtable.h
11 years ago
1) Handling string memory allocation with a new STRING class. This is only the beginning. Defining the STRING class and begining to use it (MYSQL) 2) Change the xtrace, use_tempfile and exact_info connect variables from GLOBAL to SESSION. Remaining GLOBAL variables have been made readonly. 3) Take care of LEX_STRING variables. The .str should not be regarded as allways being 0 terminated. This is handled by the Strz functions that make sure to return 0 terminated strings. Bug fix: - When inserting in MYSQL table with special column(s) a query such as: insert into t2 values(0,4,'new04'),(0,5,'new05'); failed saying: column id (the special column) not found in t2. It is now accepted but must be counted in values (these 0 are ignored) - ROWID was returning row numbers based 0. Now it is from base 1. modified: storage/connect/array.cpp storage/connect/blkfil.cpp storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamtxt.cpp storage/connect/filamvct.cpp storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/filter.cpp storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/libdoc.cpp storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/odbconn.cpp storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabdos.cpp storage/connect/tabfix.cpp storage/connect/tabfmt.cpp storage/connect/table.cpp storage/connect/tabmul.cpp storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/taboccur.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabsys.cpp storage/connect/tabtbl.cpp storage/connect/tabutil.cpp storage/connect/tabvct.cpp storage/connect/tabwmi.cpp storage/connect/tabwmi.h storage/connect/tabxcl.cpp storage/connect/tabxml.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/value.h storage/connect/xindex.cpp storage/connect/xobject.cpp storage/connect/xobject.h storage/connect/xtable.h
11 years ago
11 years ago
1) Handling string memory allocation with a new STRING class. This is only the beginning. Defining the STRING class and begining to use it (MYSQL) 2) Change the xtrace, use_tempfile and exact_info connect variables from GLOBAL to SESSION. Remaining GLOBAL variables have been made readonly. 3) Take care of LEX_STRING variables. The .str should not be regarded as allways being 0 terminated. This is handled by the Strz functions that make sure to return 0 terminated strings. Bug fix: - When inserting in MYSQL table with special column(s) a query such as: insert into t2 values(0,4,'new04'),(0,5,'new05'); failed saying: column id (the special column) not found in t2. It is now accepted but must be counted in values (these 0 are ignored) - ROWID was returning row numbers based 0. Now it is from base 1. modified: storage/connect/array.cpp storage/connect/blkfil.cpp storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamtxt.cpp storage/connect/filamvct.cpp storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/filter.cpp storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/libdoc.cpp storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/odbconn.cpp storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabdos.cpp storage/connect/tabfix.cpp storage/connect/tabfmt.cpp storage/connect/table.cpp storage/connect/tabmul.cpp storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/taboccur.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabsys.cpp storage/connect/tabtbl.cpp storage/connect/tabutil.cpp storage/connect/tabvct.cpp storage/connect/tabwmi.cpp storage/connect/tabwmi.h storage/connect/tabxcl.cpp storage/connect/tabxml.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/value.h storage/connect/xindex.cpp storage/connect/xobject.cpp storage/connect/xobject.h storage/connect/xtable.h
11 years ago
1) Handling string memory allocation with a new STRING class. This is only the beginning. Defining the STRING class and begining to use it (MYSQL) 2) Change the xtrace, use_tempfile and exact_info connect variables from GLOBAL to SESSION. Remaining GLOBAL variables have been made readonly. 3) Take care of LEX_STRING variables. The .str should not be regarded as allways being 0 terminated. This is handled by the Strz functions that make sure to return 0 terminated strings. Bug fix: - When inserting in MYSQL table with special column(s) a query such as: insert into t2 values(0,4,'new04'),(0,5,'new05'); failed saying: column id (the special column) not found in t2. It is now accepted but must be counted in values (these 0 are ignored) - ROWID was returning row numbers based 0. Now it is from base 1. modified: storage/connect/array.cpp storage/connect/blkfil.cpp storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamtxt.cpp storage/connect/filamvct.cpp storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/filter.cpp storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/libdoc.cpp storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/odbconn.cpp storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabdos.cpp storage/connect/tabfix.cpp storage/connect/tabfmt.cpp storage/connect/table.cpp storage/connect/tabmul.cpp storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/taboccur.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabsys.cpp storage/connect/tabtbl.cpp storage/connect/tabutil.cpp storage/connect/tabvct.cpp storage/connect/tabwmi.cpp storage/connect/tabwmi.h storage/connect/tabxcl.cpp storage/connect/tabxml.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/value.h storage/connect/xindex.cpp storage/connect/xobject.cpp storage/connect/xobject.h storage/connect/xtable.h
11 years ago
  1. /************ Xobject C++ Functions Source Code File (.CPP) ************/
  2. /* Name: XOBJECT.CPP Version 2.4 */
  3. /* */
  4. /* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
  5. /* */
  6. /* This file contains base XOBJECT class functions. */
  7. /* Also here is the implementation of the CONSTANT class. */
  8. /***********************************************************************/
  9. /***********************************************************************/
  10. /* Include mariaDB header file. */
  11. /***********************************************************************/
  12. #include "my_global.h"
  13. /***********************************************************************/
  14. /* Include required application header files */
  15. /* global.h is header containing all global Plug declarations. */
  16. /* plgdbsem.h is header containing the DB applic. declarations. */
  17. /***********************************************************************/
  18. #include "global.h"
  19. #include "plgdbsem.h"
  20. #include "xobject.h"
  21. /***********************************************************************/
  22. /* Macro definitions. */
  23. /***********************************************************************/
  24. #if defined(_DEBUG) || defined(DEBTRACE)
  25. #define ASSERT(B) assert(B);
  26. #else
  27. #define ASSERT(B)
  28. #endif
  29. /***********************************************************************/
  30. /* The one and only needed void object. */
  31. /***********************************************************************/
  32. XVOID Xvoid;
  33. PXOB const pXVOID = &Xvoid; // Pointer used by other classes
  34. /* ------------------------- Class XOBJECT --------------------------- */
  35. /***********************************************************************/
  36. /* GetCharValue: returns the Result value as a char string. */
  37. /* Using GetCharValue provides no conversion from numeric types. */
  38. /***********************************************************************/
  39. PSZ XOBJECT::GetCharValue(void)
  40. {
  41. ASSERT(Value)
  42. return Value->GetCharValue();
  43. } // end of GetCharValue()
  44. /***********************************************************************/
  45. /* GetShortValue: returns the Result value as a short integer. */
  46. /***********************************************************************/
  47. short XOBJECT::GetShortValue(void)
  48. {
  49. ASSERT(Value)
  50. return Value->GetShortValue();
  51. } // end of GetShortValue
  52. /***********************************************************************/
  53. /* GetIntValue: returns the Result value as a int integer. */
  54. /***********************************************************************/
  55. int XOBJECT::GetIntValue(void)
  56. {
  57. ASSERT(Value)
  58. return Value->GetIntValue();
  59. } // end of GetIntValue
  60. /***********************************************************************/
  61. /* GetFloatValue: returns the Result value as a double float. */
  62. /***********************************************************************/
  63. double XOBJECT::GetFloatValue(void)
  64. {
  65. ASSERT(Value)
  66. return Value->GetFloatValue();
  67. } // end of GetFloatValue
  68. /* ------------------------- Class CONSTANT -------------------------- */
  69. /***********************************************************************/
  70. /* CONSTANT public constructor. */
  71. /***********************************************************************/
  72. CONSTANT::CONSTANT(PGLOBAL g, void *value, short type)
  73. {
  74. if (!(Value = AllocateValue(g, value, (int)type)))
  75. longjmp(g->jumper[g->jump_level], TYPE_CONST);
  76. Constant = true;
  77. } // end of CONSTANT constructor
  78. /***********************************************************************/
  79. /* CONSTANT public constructor. */
  80. /***********************************************************************/
  81. CONSTANT::CONSTANT(PGLOBAL g, int n)
  82. {
  83. if (!(Value = AllocateValue(g, &n, TYPE_INT)))
  84. longjmp(g->jumper[g->jump_level], TYPE_CONST);
  85. Constant = true;
  86. } // end of CONSTANT constructor
  87. /***********************************************************************/
  88. /* GetLengthEx: returns an evaluation of the constant string length. */
  89. /* Note: When converting from token to string, length has to be */
  90. /* specified but we need the domain length, not the value length. */
  91. /***********************************************************************/
  92. int CONSTANT::GetLengthEx(void)
  93. {
  94. return Value->GetValLen();
  95. } // end of GetLengthEx
  96. /***********************************************************************/
  97. /* Convert a constant to the given type. */
  98. /***********************************************************************/
  99. void CONSTANT::Convert(PGLOBAL g, int newtype)
  100. {
  101. if (Value->GetType() != newtype)
  102. if (!(Value = AllocateValue(g, Value, newtype)))
  103. longjmp(g->jumper[g->jump_level], TYPE_CONST);
  104. } // end of Convert
  105. /***********************************************************************/
  106. /* Compare: returns true if this object is equivalent to xp. */
  107. /***********************************************************************/
  108. bool CONSTANT::Compare(PXOB xp)
  109. {
  110. if (this == xp)
  111. return true;
  112. else if (xp->GetType() != TYPE_CONST)
  113. return false;
  114. else
  115. return Value->IsEqual(xp->GetValue(), true);
  116. } // end of Compare
  117. #if 0
  118. /***********************************************************************/
  119. /* Rephrase: temporary implementation used by PlugRephraseSQL. */
  120. /***********************************************************************/
  121. bool CONSTANT::Rephrase(PGLOBAL g, PSZ work)
  122. {
  123. switch (Value->GetType()) {
  124. case TYPE_STRING:
  125. sprintf(work + strlen(work), "'%s'", Value->GetCharValue());
  126. break;
  127. case TYPE_SHORT:
  128. sprintf(work + strlen(work), "%hd", Value->GetShortValue());
  129. break;
  130. case TYPE_INT:
  131. case TYPE_DATE:
  132. sprintf(work + strlen(work), "%d", Value->GetIntValue());
  133. break;
  134. case TYPE_DOUBLE:
  135. sprintf(work + strlen(work), "%lf", Value->GetFloatValue());
  136. break;
  137. case TYPE_BIGINT:
  138. sprintf(work + strlen(work), "%lld", Value->GetBigintValue());
  139. break;
  140. case TYPE_TINY:
  141. sprintf(work + strlen(work), "%d", Value->GetTinyValue());
  142. break;
  143. default:
  144. sprintf(g->Message, MSG(BAD_CONST_TYPE), Value->GetType());
  145. return false;
  146. } // endswitch
  147. return false;
  148. } // end of Rephrase
  149. #endif // 0
  150. /***********************************************************************/
  151. /* Make file output of a constant object. */
  152. /***********************************************************************/
  153. void CONSTANT::Print(PGLOBAL g, FILE *f, uint n)
  154. {
  155. Value->Print(g, f, n);
  156. } /* end of Print */
  157. /***********************************************************************/
  158. /* Make string output of a constant object. */
  159. /***********************************************************************/
  160. void CONSTANT::Print(PGLOBAL g, char *ps, uint z)
  161. {
  162. Value->Print(g, ps, z);
  163. } /* end of Print */
  164. /* -------------------------- Class STRING --------------------------- */
  165. /***********************************************************************/
  166. /* STRING public constructor for new char values. Alloc Size must be */
  167. /* calculated because PlugSubAlloc rounds up size to multiple of 8. */
  168. /***********************************************************************/
  169. STRING::STRING(PGLOBAL g, uint n, char *str)
  170. {
  171. G = g;
  172. Length = (str) ? strlen(str) : 0;
  173. if ((Strp = (PSZ)PlgDBSubAlloc(g, NULL, MY_MAX(n, Length) + 1))) {
  174. if (str)
  175. strcpy(Strp, str);
  176. else
  177. *Strp = 0;
  178. Next = GetNext();
  179. Size = Next - Strp;
  180. } else {
  181. // This should normally never happen
  182. Next = NULL;
  183. Size = 0;
  184. } // endif Strp
  185. } // end of STRING constructor
  186. /***********************************************************************/
  187. /* Reallocate the string memory and return the (new) position. */
  188. /* If Next is equal to GetNext() this means that no new suballocation */
  189. /* has been done. Then we can just increase the size of the current */
  190. /* allocation and the Strp will remain pointing to the same memory. */
  191. /***********************************************************************/
  192. char *STRING::Realloc(uint len)
  193. {
  194. char *p;
  195. bool b = (Next == GetNext());
  196. p = (char*)PlgDBSubAlloc(G, NULL, b ? len - Size : len);
  197. if (!p) {
  198. // No more room in Sarea; this is very unlikely
  199. strcpy(G->Message, "No more room in work area");
  200. return NULL;
  201. } // endif p
  202. if (b)
  203. p = Strp;
  204. Next = GetNext();
  205. Size = Next - p;
  206. return p;
  207. } // end of Realloc
  208. /***********************************************************************/
  209. /* Set a STRING new PSZ value. */
  210. /***********************************************************************/
  211. bool STRING::Set(PSZ s)
  212. {
  213. if (!s)
  214. return false;
  215. uint len = strlen(s) + 1;
  216. if (len > Size) {
  217. char *p = Realloc(len);
  218. if (!p)
  219. return true;
  220. else
  221. Strp = p;
  222. } // endif n
  223. strcpy(Strp, s);
  224. Length = len - 1;
  225. return false;
  226. } // end of Set
  227. /***********************************************************************/
  228. /* Set a STRING new PSZ value. */
  229. /***********************************************************************/
  230. bool STRING::Set(char *s, uint n)
  231. {
  232. if (!s)
  233. return false;
  234. uint len = strnlen(s, n) + 1;
  235. if (len > Size) {
  236. char *p = Realloc(len);
  237. if (!p)
  238. return true;
  239. else
  240. Strp = p;
  241. } // endif n
  242. strncpy(Strp, s, n);
  243. Length = len - 1;
  244. return false;
  245. } // end of Set
  246. /***********************************************************************/
  247. /* Append a char* to a STRING. */
  248. /***********************************************************************/
  249. bool STRING::Append(const char *s, uint ln)
  250. {
  251. if (!s)
  252. return false;
  253. uint len = Length + ln + 1;
  254. if (len > Size) {
  255. char *p = Realloc(len);
  256. if (!p)
  257. return true;
  258. else if (p != Strp) {
  259. strcpy(p, Strp);
  260. Strp = p;
  261. } // endif p
  262. } // endif n
  263. strncpy(Strp + Length, s, ln);
  264. Length = len - 1;
  265. Strp[Length] = 0;
  266. return false;
  267. } // end of Append
  268. /***********************************************************************/
  269. /* Append a PSZ to a STRING. */
  270. /***********************************************************************/
  271. bool STRING::Append(PSZ s)
  272. {
  273. if (!s)
  274. return false;
  275. uint len = Length + strlen(s) + 1;
  276. if (len > Size) {
  277. char *p = Realloc(len);
  278. if (!p)
  279. return true;
  280. else if (p != Strp) {
  281. strcpy(p, Strp);
  282. Strp = p;
  283. } // endif p
  284. } // endif n
  285. strcpy(Strp + Length, s);
  286. Length = len - 1;
  287. return false;
  288. } // end of Append
  289. /***********************************************************************/
  290. /* Append a STRING to a STRING. */
  291. /***********************************************************************/
  292. bool STRING::Append(STRING &str)
  293. {
  294. return Append(str.GetStr());
  295. } // end of Append
  296. /***********************************************************************/
  297. /* Append a char to a STRING. */
  298. /***********************************************************************/
  299. bool STRING::Append(char c)
  300. {
  301. if (Length + 2 > Size) {
  302. char *p = Realloc(Length + 2);
  303. if (!p)
  304. return true;
  305. else if (p != Strp) {
  306. strcpy(p, Strp);
  307. Strp = p;
  308. } // endif p
  309. } // endif n
  310. Strp[Length++] = c;
  311. Strp[Length] = 0;
  312. return false;
  313. } // end of Append
  314. /***********************************************************************/
  315. /* Append a quoted PSZ to a STRING. */
  316. /***********************************************************************/
  317. bool STRING::Append_quoted(PSZ s)
  318. {
  319. bool b = Append('\'');
  320. if (s) for (char *p = s; !b && *p; p++)
  321. switch (*p) {
  322. case '\'':
  323. case '\\':
  324. case '\t':
  325. case '\n':
  326. case '\r':
  327. case '\b':
  328. case '\f': b |= Append('\\');
  329. // passthru
  330. default:
  331. b |= Append(*p);
  332. break;
  333. } // endswitch *p
  334. return (b |= Append('\''));
  335. } // end of Append_quoted
  336. /***********************************************************************/
  337. /* Resize to given length but only when last suballocated. */
  338. /* New size should be greater than string length. */
  339. /***********************************************************************/
  340. bool STRING::Resize(uint newsize)
  341. {
  342. if (Next == GetNext() && newsize > Length) {
  343. uint nsz = (((signed)newsize + 7) / 8) * 8;
  344. int diff = (signed)Size - (signed)nsz;
  345. PPOOLHEADER pp = (PPOOLHEADER)G->Sarea;
  346. if ((signed)pp->FreeBlk + diff < 0)
  347. return true; // Out of memory
  348. pp->To_Free -= diff;
  349. pp->FreeBlk += diff;
  350. Size = nsz;
  351. return false;
  352. } else
  353. return newsize > Size;
  354. } // end of Resize