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.

2904 lines
89 KiB

Change all preprocessor compiler directives to use __WIN__ as the mean of specifying Windows or not Windows compile. This is what MariaDB does. modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/fmdlex.c modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/json.cpp modified: storage/connect/macutil.cpp modified: storage/connect/macutil.h modified: storage/connect/maputil.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/myconn.h modified: storage/connect/myutil.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/os.h modified: storage/connect/osutil.c modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.c modified: storage/connect/rcmsg.c modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmac.h modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h modified: storage/connect/tabmysql.cpp modified: storage/connect/taboccur.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h
11 years ago
Change all preprocessor compiler directives to use __WIN__ as the mean of specifying Windows or not Windows compile. This is what MariaDB does. modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/fmdlex.c modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/json.cpp modified: storage/connect/macutil.cpp modified: storage/connect/macutil.h modified: storage/connect/maputil.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/myconn.h modified: storage/connect/myutil.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/os.h modified: storage/connect/osutil.c modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.c modified: storage/connect/rcmsg.c modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmac.h modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h modified: storage/connect/tabmysql.cpp modified: storage/connect/taboccur.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h
11 years ago
Change all preprocessor compiler directives to use __WIN__ as the mean of specifying Windows or not Windows compile. This is what MariaDB does. modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/fmdlex.c modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/json.cpp modified: storage/connect/macutil.cpp modified: storage/connect/macutil.h modified: storage/connect/maputil.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/myconn.h modified: storage/connect/myutil.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/os.h modified: storage/connect/osutil.c modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.c modified: storage/connect/rcmsg.c modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmac.h modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h modified: storage/connect/tabmysql.cpp modified: storage/connect/taboccur.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h
11 years ago
- NOTE: an experimental implementation of MRR was done but not kept in this version. Sure enough, it never caused any improvement in the execution speed and rather caused a small increase of execution time. This is probably because values are sorted by rowid in each range of CONNECT indexes. This could be reconsidered if a customer have a need for processing very big files. - Fix a bug in ha_connect::CheckCond. The negated form of BETWEEN and IS NULL operators was not recognized. modified: storage/connect/ha_connect.cc - Add long jump initialization in CntReadNext. This was causing a server crash when an error occured in a ReadColumn. modified: storage/connect/connect.cc - General cleanup of CONNECT source code eliminating all code not used by CONNECT, including the MRR test code (saved separately). modified: storage/connect/catalog.h storage/connect/colblk.cpp storage/connect/colblk.h storage/connect/connect.cc storage/connect/connect.h storage/connect/domdoc.h storage/connect/filamap.cpp storage/connect/filamap.h storage/connect/filamdbf.h storage/connect/filamfix.cpp storage/connect/filamfix.h storage/connect/filamtxt.cpp storage/connect/filamtxt.h storage/connect/filamvct.cpp storage/connect/filamvct.h storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/myconn.h storage/connect/plgcnx.h storage/connect/plgdbsem.h storage/connect/plugutil.c storage/connect/preparse.h storage/connect/reldef.cpp storage/connect/reldef.h storage/connect/tabcol.h storage/connect/tabdos.cpp storage/connect/tabdos.h storage/connect/tabfix.cpp storage/connect/tabfmt.cpp storage/connect/tabfmt.h storage/connect/table.cpp storage/connect/tabmac.h storage/connect/tabmul.h storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/taboccur.h storage/connect/tabodbc.cpp storage/connect/tabodbc.h storage/connect/tabsys.cpp storage/connect/tabsys.h storage/connect/tabtbl.cpp storage/connect/tabtbl.h storage/connect/tabutil.h storage/connect/tabvct.cpp storage/connect/tabvct.h storage/connect/tabwmi.cpp storage/connect/tabwmi.h storage/connect/tabxml.cpp storage/connect/tabxml.h storage/connect/user_connect.cc storage/connect/user_connect.h storage/connect/valblk.cpp storage/connect/valblk.h storage/connect/value.cpp storage/connect/value.h storage/connect/xindex.cpp storage/connect/xindex.h storage/connect/xobject.cpp storage/connect/xobject.h storage/connect/xtable.h
12 years ago
Change all preprocessor compiler directives to use __WIN__ as the mean of specifying Windows or not Windows compile. This is what MariaDB does. modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/fmdlex.c modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/json.cpp modified: storage/connect/macutil.cpp modified: storage/connect/macutil.h modified: storage/connect/maputil.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/myconn.h modified: storage/connect/myutil.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/os.h modified: storage/connect/osutil.c modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.c modified: storage/connect/rcmsg.c modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmac.h modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h modified: storage/connect/tabmysql.cpp modified: storage/connect/taboccur.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h
11 years ago
Change all preprocessor compiler directives to use __WIN__ as the mean of specifying Windows or not Windows compile. This is what MariaDB does. modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/fmdlex.c modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/json.cpp modified: storage/connect/macutil.cpp modified: storage/connect/macutil.h modified: storage/connect/maputil.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/myconn.h modified: storage/connect/myutil.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/os.h modified: storage/connect/osutil.c modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.c modified: storage/connect/rcmsg.c modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmac.h modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h modified: storage/connect/tabmysql.cpp modified: storage/connect/taboccur.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h
11 years ago
This is a major update that fixes most of the issues and bugs that have been created by the last addition of new CONNECT features. The version previous to this one is a preliminary test version and should not be distributed. - Handle indexed UPDATE/DELETE. Previously this was just tested and an error message send when it could not be done. Now CONNECT can do it in all the cases. It is done by a MRR like tchnique by making a list of all update or delete to do, sort them, then execute them. modified: storage/connect/array.cpp storage/connect/array.h storage/connect/filamap.cpp storage/connect/filamap.h storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamfix.h storage/connect/filamtxt.cpp storage/connect/filamtxt.h storage/connect/filamvct.cpp storage/connect/filamvct.h storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h - Differenciate Cardinality that returns a true or estimated table size and GetMaxSize that return a value equal or greater than the table row number. This fixes the errors of non matching opt files. modified: storage/connect/connect.cc storage/connect/tabdos.cpp storage/connect/tabdos.h storage/connect/tabfix.cpp storage/connect/table.cpp storage/connect/tabmac.h storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/tabodbc.cpp storage/connect/tabodbc.h storage/connect/tabpivot.h storage/connect/tabtbl.cpp storage/connect/tabtbl.h storage/connect/tabutil.cpp storage/connect/tabutil.h storage/connect/tabwmi.h storage/connect/xtable.h - Fix some errors and issues when making index and opt files. Erase opt and index files for void tables. Fix wrong calculation of Block and Last in MakeBlockValues. Invalidate indexes before making opt file. Fully handle blocked variable tables. Make opt file for blocked variable tables even when they have no optimised colums. modified: storage/connect/tabdos.cpp storage/connect/xindex.h - Fix some errors making index Return an error when the allocation is too small (should not really occur now that GetMaxSize is sure) Don't use XXROW index for DBF tables because of soft deleted lines. modified: storage/connect/xindex.cpp - Typo modified: storage/connect/macutil.cpp storage/connect/tabdos.h storage/connect/tabsys.cpp storage/connect/tabsys.h
11 years ago
This is a major update that fixes most of the issues and bugs that have been created by the last addition of new CONNECT features. The version previous to this one is a preliminary test version and should not be distributed. - Handle indexed UPDATE/DELETE. Previously this was just tested and an error message send when it could not be done. Now CONNECT can do it in all the cases. It is done by a MRR like tchnique by making a list of all update or delete to do, sort them, then execute them. modified: storage/connect/array.cpp storage/connect/array.h storage/connect/filamap.cpp storage/connect/filamap.h storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamfix.h storage/connect/filamtxt.cpp storage/connect/filamtxt.h storage/connect/filamvct.cpp storage/connect/filamvct.h storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h - Differenciate Cardinality that returns a true or estimated table size and GetMaxSize that return a value equal or greater than the table row number. This fixes the errors of non matching opt files. modified: storage/connect/connect.cc storage/connect/tabdos.cpp storage/connect/tabdos.h storage/connect/tabfix.cpp storage/connect/table.cpp storage/connect/tabmac.h storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/tabodbc.cpp storage/connect/tabodbc.h storage/connect/tabpivot.h storage/connect/tabtbl.cpp storage/connect/tabtbl.h storage/connect/tabutil.cpp storage/connect/tabutil.h storage/connect/tabwmi.h storage/connect/xtable.h - Fix some errors and issues when making index and opt files. Erase opt and index files for void tables. Fix wrong calculation of Block and Last in MakeBlockValues. Invalidate indexes before making opt file. Fully handle blocked variable tables. Make opt file for blocked variable tables even when they have no optimised colums. modified: storage/connect/tabdos.cpp storage/connect/xindex.h - Fix some errors making index Return an error when the allocation is too small (should not really occur now that GetMaxSize is sure) Don't use XXROW index for DBF tables because of soft deleted lines. modified: storage/connect/xindex.cpp - Typo modified: storage/connect/macutil.cpp storage/connect/tabdos.h storage/connect/tabsys.cpp storage/connect/tabsys.h
11 years ago
This is a major update that fixes most of the issues and bugs that have been created by the last addition of new CONNECT features. The version previous to this one is a preliminary test version and should not be distributed. - Handle indexed UPDATE/DELETE. Previously this was just tested and an error message send when it could not be done. Now CONNECT can do it in all the cases. It is done by a MRR like tchnique by making a list of all update or delete to do, sort them, then execute them. modified: storage/connect/array.cpp storage/connect/array.h storage/connect/filamap.cpp storage/connect/filamap.h storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamfix.h storage/connect/filamtxt.cpp storage/connect/filamtxt.h storage/connect/filamvct.cpp storage/connect/filamvct.h storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h - Differenciate Cardinality that returns a true or estimated table size and GetMaxSize that return a value equal or greater than the table row number. This fixes the errors of non matching opt files. modified: storage/connect/connect.cc storage/connect/tabdos.cpp storage/connect/tabdos.h storage/connect/tabfix.cpp storage/connect/table.cpp storage/connect/tabmac.h storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/tabodbc.cpp storage/connect/tabodbc.h storage/connect/tabpivot.h storage/connect/tabtbl.cpp storage/connect/tabtbl.h storage/connect/tabutil.cpp storage/connect/tabutil.h storage/connect/tabwmi.h storage/connect/xtable.h - Fix some errors and issues when making index and opt files. Erase opt and index files for void tables. Fix wrong calculation of Block and Last in MakeBlockValues. Invalidate indexes before making opt file. Fully handle blocked variable tables. Make opt file for blocked variable tables even when they have no optimised colums. modified: storage/connect/tabdos.cpp storage/connect/xindex.h - Fix some errors making index Return an error when the allocation is too small (should not really occur now that GetMaxSize is sure) Don't use XXROW index for DBF tables because of soft deleted lines. modified: storage/connect/xindex.cpp - Typo modified: storage/connect/macutil.cpp storage/connect/tabdos.h storage/connect/tabsys.cpp storage/connect/tabsys.h
11 years ago
This is a major update that fixes most of the issues and bugs that have been created by the last addition of new CONNECT features. The version previous to this one is a preliminary test version and should not be distributed. - Handle indexed UPDATE/DELETE. Previously this was just tested and an error message send when it could not be done. Now CONNECT can do it in all the cases. It is done by a MRR like tchnique by making a list of all update or delete to do, sort them, then execute them. modified: storage/connect/array.cpp storage/connect/array.h storage/connect/filamap.cpp storage/connect/filamap.h storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamfix.h storage/connect/filamtxt.cpp storage/connect/filamtxt.h storage/connect/filamvct.cpp storage/connect/filamvct.h storage/connect/filamzip.cpp storage/connect/filamzip.h storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h - Differenciate Cardinality that returns a true or estimated table size and GetMaxSize that return a value equal or greater than the table row number. This fixes the errors of non matching opt files. modified: storage/connect/connect.cc storage/connect/tabdos.cpp storage/connect/tabdos.h storage/connect/tabfix.cpp storage/connect/table.cpp storage/connect/tabmac.h storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/tabodbc.cpp storage/connect/tabodbc.h storage/connect/tabpivot.h storage/connect/tabtbl.cpp storage/connect/tabtbl.h storage/connect/tabutil.cpp storage/connect/tabutil.h storage/connect/tabwmi.h storage/connect/xtable.h - Fix some errors and issues when making index and opt files. Erase opt and index files for void tables. Fix wrong calculation of Block and Last in MakeBlockValues. Invalidate indexes before making opt file. Fully handle blocked variable tables. Make opt file for blocked variable tables even when they have no optimised colums. modified: storage/connect/tabdos.cpp storage/connect/xindex.h - Fix some errors making index Return an error when the allocation is too small (should not really occur now that GetMaxSize is sure) Don't use XXROW index for DBF tables because of soft deleted lines. modified: storage/connect/xindex.cpp - Typo modified: storage/connect/macutil.cpp storage/connect/tabdos.h storage/connect/tabsys.cpp storage/connect/tabsys.h
11 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
- FIX PIVOT bug MDEV-5869 caused by using fop (field option ptr) when NULL. modified: storage/connect/ha_connect.cc - Suppress the use of connect.in by adding the connect_xtrace system variable. modified: storage/connect/ha_connect.cc - Make column length, varchar, and temporal column types recognized in discovery when using SRCDEF,or PIVOT. modified: storage/connect/ha_connect.cc storage/connect/myconn.cpp storage/connect/myutil.cpp storage/connect/plgdbsem.h - Avoid (rare) crash when using DECIMAL type. (buf was too small) modified: storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/valblk.cpp storage/connect/value.cpp - General cleaning of unused code, standardize tracing, and update version number modified: storage/connect/block.h storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/csort.h storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamzip.cpp storage/connect/ha_connect.cc storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/mysql-test/connect/r/alter.result storage/connect/mysql-test/connect/r/xml.result storage/connect/myutil.cpp storage/connect/osutil.c storage/connect/plgdbsem.h storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabvct.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/xindex.cpp
12 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: 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) 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
This is a major update of CONNECT that goes from version 1.1 to 1.2 =================================================================== - Implement a first support of the ALTER TABLE command. This fixes MDEV-5440 but does much more than only that. See the details of how ALTER is supported in the new documentation and also in MDEV-5440 comment. This is done principally by implementing for CONNECT the virtual function check_if_supported_inplace_alter. modified: storage/connect/connect.cc storage/connect/global.h storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/mysql-test/connect/r/bin.result storage/connect/mysql-test/connect/r/csv.result storage/connect/mysql-test/connect/r/dbf.result storage/connect/mysql-test/connect/r/dir.result storage/connect/mysql-test/connect/r/fix.result storage/connect/mysql-test/connect/r/index.result storage/connect/mysql-test/connect/r/ini.result storage/connect/mysql-test/connect/r/occur.result storage/connect/mysql-test/connect/r/pivot.result storage/connect/mysql-test/connect/r/vec.result storage/connect/mysql-test/connect/t/dbf.test storage/connect/plugutil.c storage/connect/user_connect.cc - Fixes the tabname/table_name issue for XML tables. Implement multiple files XML tables. modified: storage/connect/tabxml.cpp storage/connect/tabxml.h - Set to varchar(256) the fields of catalog tables stored as STRBLK's (had length 0 --> CHAR(1)) Add the GetCharString function to the VALBLK class modified: storage/connect/ha_connect.cc storage/connect/valblk.cpp storage/connect/valblk.h storage/connect/value.cpp - Translate CONNECT error messages to system_charset to avoid truncation on not ASCII characters. modified: storage/connect/ha_connect.cc - Update version number modified: storage/connect/ha_connect.cc storage/connect/mysql-test/connect/r/xml.result - Move the TDBASE::data_charset body from xtable.h to table.cpp. (dont' remember why) modified: storage/connect/table.cpp storage/connect/xtable.h - Other modifications are to enhance the support of OEM tables. In particular, they can now provide column definition in dicovery. modified: storage/connect/colblk.h storage/connect/global.h storage/connect/ha_connect.cc storage/connect/mycat.cc storage/connect/plgcnx.h storage/connect/plgdbsem.h storage/connect/xtable.h - Or to add or modify tracing. modified: storage/connect/filamtxt.cpp storage/connect/ha_connect.cc storage/connect/plgdbutl.cpp storage/connect/tabfix.cpp storage/connect/tabmysql.cpp
12 years ago
- FIX PIVOT bug MDEV-5869 caused by using fop (field option ptr) when NULL. modified: storage/connect/ha_connect.cc - Suppress the use of connect.in by adding the connect_xtrace system variable. modified: storage/connect/ha_connect.cc - Make column length, varchar, and temporal column types recognized in discovery when using SRCDEF,or PIVOT. modified: storage/connect/ha_connect.cc storage/connect/myconn.cpp storage/connect/myutil.cpp storage/connect/plgdbsem.h - Avoid (rare) crash when using DECIMAL type. (buf was too small) modified: storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/valblk.cpp storage/connect/value.cpp - General cleaning of unused code, standardize tracing, and update version number modified: storage/connect/block.h storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/csort.h storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamzip.cpp storage/connect/ha_connect.cc storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/mysql-test/connect/r/alter.result storage/connect/mysql-test/connect/r/xml.result storage/connect/myutil.cpp storage/connect/osutil.c storage/connect/plgdbsem.h storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabvct.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/xindex.cpp
12 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
- FIX PIVOT bug MDEV-5869 caused by using fop (field option ptr) when NULL. modified: storage/connect/ha_connect.cc - Suppress the use of connect.in by adding the connect_xtrace system variable. modified: storage/connect/ha_connect.cc - Make column length, varchar, and temporal column types recognized in discovery when using SRCDEF,or PIVOT. modified: storage/connect/ha_connect.cc storage/connect/myconn.cpp storage/connect/myutil.cpp storage/connect/plgdbsem.h - Avoid (rare) crash when using DECIMAL type. (buf was too small) modified: storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/valblk.cpp storage/connect/value.cpp - General cleaning of unused code, standardize tracing, and update version number modified: storage/connect/block.h storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/csort.h storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamzip.cpp storage/connect/ha_connect.cc storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/mysql-test/connect/r/alter.result storage/connect/mysql-test/connect/r/xml.result storage/connect/myutil.cpp storage/connect/osutil.c storage/connect/plgdbsem.h storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabvct.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/xindex.cpp
12 years ago
Change all preprocessor compiler directives to use __WIN__ as the mean of specifying Windows or not Windows compile. This is what MariaDB does. modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/fmdlex.c modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/json.cpp modified: storage/connect/macutil.cpp modified: storage/connect/macutil.h modified: storage/connect/maputil.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/myconn.h modified: storage/connect/myutil.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/os.h modified: storage/connect/osutil.c modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.c modified: storage/connect/rcmsg.c modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmac.h modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h modified: storage/connect/tabmysql.cpp modified: storage/connect/taboccur.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h
11 years ago
Change all preprocessor compiler directives to use __WIN__ as the mean of specifying Windows or not Windows compile. This is what MariaDB does. modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/domdoc.cpp modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/fmdlex.c modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/json.cpp modified: storage/connect/macutil.cpp modified: storage/connect/macutil.h modified: storage/connect/maputil.cpp modified: storage/connect/mycat.cc modified: storage/connect/myconn.cpp modified: storage/connect/myconn.h modified: storage/connect/myutil.cpp modified: storage/connect/odbconn.cpp modified: storage/connect/odbconn.h modified: storage/connect/os.h modified: storage/connect/osutil.c modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.c modified: storage/connect/rcmsg.c modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabmac.cpp modified: storage/connect/tabmac.h modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h modified: storage/connect/tabmysql.cpp modified: storage/connect/taboccur.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabutil.cpp modified: storage/connect/tabvct.cpp modified: storage/connect/tabwmi.cpp modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/valblk.cpp modified: storage/connect/value.cpp modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h
11 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
- FIX PIVOT bug MDEV-5869 caused by using fop (field option ptr) when NULL. modified: storage/connect/ha_connect.cc - Suppress the use of connect.in by adding the connect_xtrace system variable. modified: storage/connect/ha_connect.cc - Make column length, varchar, and temporal column types recognized in discovery when using SRCDEF,or PIVOT. modified: storage/connect/ha_connect.cc storage/connect/myconn.cpp storage/connect/myutil.cpp storage/connect/plgdbsem.h - Avoid (rare) crash when using DECIMAL type. (buf was too small) modified: storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/valblk.cpp storage/connect/value.cpp - General cleaning of unused code, standardize tracing, and update version number modified: storage/connect/block.h storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/csort.h storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamzip.cpp storage/connect/ha_connect.cc storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/mysql-test/connect/r/alter.result storage/connect/mysql-test/connect/r/xml.result storage/connect/myutil.cpp storage/connect/osutil.c storage/connect/plgdbsem.h storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabvct.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/xindex.cpp
12 years ago
- FIX PIVOT bug MDEV-5869 caused by using fop (field option ptr) when NULL. modified: storage/connect/ha_connect.cc - Suppress the use of connect.in by adding the connect_xtrace system variable. modified: storage/connect/ha_connect.cc - Make column length, varchar, and temporal column types recognized in discovery when using SRCDEF,or PIVOT. modified: storage/connect/ha_connect.cc storage/connect/myconn.cpp storage/connect/myutil.cpp storage/connect/plgdbsem.h - Avoid (rare) crash when using DECIMAL type. (buf was too small) modified: storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/valblk.cpp storage/connect/value.cpp - General cleaning of unused code, standardize tracing, and update version number modified: storage/connect/block.h storage/connect/colblk.cpp storage/connect/connect.cc storage/connect/csort.h storage/connect/filamap.cpp storage/connect/filamdbf.cpp storage/connect/filamfix.cpp storage/connect/filamzip.cpp storage/connect/ha_connect.cc storage/connect/mycat.cc storage/connect/myconn.cpp storage/connect/mysql-test/connect/r/alter.result storage/connect/mysql-test/connect/r/xml.result storage/connect/myutil.cpp storage/connect/osutil.c storage/connect/plgdbsem.h storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/reldef.cpp storage/connect/tabcol.cpp storage/connect/tabfmt.cpp storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabvct.cpp storage/connect/user_connect.cc storage/connect/valblk.cpp storage/connect/value.cpp storage/connect/xindex.cpp
12 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
Get rid of GCC warnings about unused parameters modified: storage/connect/array.cpp modified: storage/connect/blkfil.cpp modified: storage/connect/block.h modified: storage/connect/catalog.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/connect.cc modified: storage/connect/filamap.cpp modified: storage/connect/filamdbf.cpp modified: storage/connect/filamfix.cpp modified: storage/connect/filamtxt.cpp modified: storage/connect/filamtxt.h modified: storage/connect/filamvct.cpp modified: storage/connect/filamzip.cpp modified: storage/connect/filter.h modified: storage/connect/ha_connect.c modified: storage/connect/jsonudf.cpp modified: storage/connect/mycat.h modified: storage/connect/myconn.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/reldef.cpp modified: storage/connect/reldef.h modified: storage/connect/tabcol.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/table.cpp modified: storage/connect/tabmul.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabmysql.h modified: storage/connect/taboccur.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabsys.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabtbl.h modified: storage/connect/tabutil.cpp modified: storage/connect/tabutil.h modified: storage/connect/tabvct.cpp modified: storage/connect/tabvir.cpp modified: storage/connect/tabvir.h modified: storage/connect/tabxcl.cpp modified: storage/connect/tabxcl.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h modified: storage/connect/valblk.cpp modified: storage/connect/valblk.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.h modified: storage/connect/xtable.h
11 years ago
  1. /************* Value C++ Functions Source Code File (.CPP) *************/
  2. /* Name: VALUE.CPP Version 2.6 */
  3. /* */
  4. /* (C) Copyright to the author Olivier BERTRAND 2001-2016 */
  5. /* */
  6. /* This file contains the VALUE and derived classes family functions. */
  7. /* These classes contain values of different types. They are used so */
  8. /* new object types can be defined and added to the processing simply */
  9. /* (hopefully) adding their specific functions in this file. */
  10. /* First family is VALUE that represent single typed objects. It is */
  11. /* used by columns (COLBLK), SELECT and FILTER (derived) objects. */
  12. /* Second family is VALBLK, representing simple suballocated arrays */
  13. /* of values treated sequentially by FIX, BIN and VCT tables and */
  14. /* columns, as well for min/max blocks as for VCT column blocks. */
  15. /* Q&A: why not using only one family ? Simple values are arrays that */
  16. /* have only one element and arrays could have functions for all kind */
  17. /* of processing. The answer is a-because historically it was simpler */
  18. /* to do that way, b-because of performance on single values, and c- */
  19. /* to avoid too complicated classes and unuseful duplication of many */
  20. /* functions used on one family only. The drawback is that for new */
  21. /* types of objects, we shall have more classes to update. */
  22. /* Currently the only implemented types are STRING, INT, SHORT, TINY, */
  23. /* DATE and LONGLONG. Recently we added some UNSIGNED types. */
  24. /***********************************************************************/
  25. /***********************************************************************/
  26. /* Include relevant MariaDB header file. */
  27. /***********************************************************************/
  28. #include "my_global.h"
  29. #include "sql_class.h"
  30. #include "sql_time.h"
  31. #if defined(__WIN__)
  32. //#include <windows.h>
  33. #else // !__WIN__
  34. #include <string.h>
  35. #endif // !__WIN__
  36. #include <math.h>
  37. #undef DOMAIN // Was defined in math.h
  38. /***********************************************************************/
  39. /* Include required application header files */
  40. /* global.h is header containing all global Plug declarations. */
  41. /* plgdbsem.h is header containing the DB applic. declarations. */
  42. /***********************************************************************/
  43. #include "global.h"
  44. #include "plgdbsem.h"
  45. #include "preparse.h" // For DATPAR
  46. #include "valblk.h"
  47. #define NO_FUNC // Already defined in ODBConn
  48. #include "plgcnx.h" // For DB types
  49. #include "osutil.h"
  50. /***********************************************************************/
  51. /* Check macro's. */
  52. /***********************************************************************/
  53. #if defined(_DEBUG)
  54. #define CheckType(V) if (Type != V->GetType()) { \
  55. PGLOBAL& g = Global; \
  56. strcpy(g->Message, MSG(VALTYPE_NOMATCH)); \
  57. longjmp(g->jumper[g->jump_level], Type); }
  58. #else
  59. #define CheckType(V)
  60. #endif
  61. #define FOURYEARS 126230400 // Four years in seconds (1 leap)
  62. /***********************************************************************/
  63. /* Initialize the DTVAL static member. */
  64. /***********************************************************************/
  65. int DTVAL::Shift = 0;
  66. /***********************************************************************/
  67. /* Routines called externally. */
  68. /***********************************************************************/
  69. bool PlugEvalLike(PGLOBAL, LPCSTR, LPCSTR, bool);
  70. #if !defined(__WIN__)
  71. extern "C" {
  72. PSZ strupr(PSZ s);
  73. PSZ strlwr(PSZ s);
  74. }
  75. #endif // !__WIN__
  76. /***********************************************************************/
  77. /* Get a long long number from its character representation. */
  78. /* IN p: Pointer to the numeric string */
  79. /* IN n: The string length */
  80. /* IN maxval: The number max value */
  81. /* IN un: True if the number must be unsigned */
  82. /* OUT rc: Set to TRUE for out of range value */
  83. /* OUT minus: Set to true if the number is negative */
  84. /* Returned val: The resulting number */
  85. /***********************************************************************/
  86. ulonglong CharToNumber(char *p, int n, ulonglong maxval,
  87. bool un, bool *minus, bool *rc)
  88. {
  89. char *p2;
  90. uchar c;
  91. ulonglong val;
  92. if (minus) *minus = false;
  93. if (rc) *rc = false;
  94. if (n <= 0) return 0LL;
  95. // Eliminate leading blanks or 0
  96. for (p2 = p + n; p < p2 && (*p == ' ' || *p == '0'); p++) ;
  97. // Get an eventual sign character
  98. switch (*p) {
  99. case '-':
  100. if (un) {
  101. if (rc) *rc = true;
  102. return 0;
  103. } else {
  104. maxval++;
  105. if (minus) *minus = true;
  106. } // endif Unsigned
  107. /* fall through */
  108. case '+':
  109. p++;
  110. break;
  111. } // endswitch *p
  112. for (val = 0; p < p2 && (c = (uchar)(*p - '0')) < 10; p++)
  113. if (val > (maxval - c) / 10) {
  114. val = maxval;
  115. if (rc) *rc = true;
  116. break;
  117. } else
  118. val = val * 10 + c;
  119. return val;
  120. } // end of CharToNumber
  121. /***********************************************************************/
  122. /* GetTypeName: returns the PlugDB internal type name. */
  123. /***********************************************************************/
  124. PSZ GetTypeName(int type)
  125. {
  126. PSZ name;
  127. switch (type) {
  128. case TYPE_STRING: name = "CHAR"; break;
  129. case TYPE_SHORT: name = "SMALLINT"; break;
  130. case TYPE_INT: name = "INTEGER"; break;
  131. case TYPE_BIGINT: name = "BIGINT"; break;
  132. case TYPE_DATE: name = "DATE"; break;
  133. case TYPE_DOUBLE: name = "DOUBLE"; break;
  134. case TYPE_TINY: name = "TINY"; break;
  135. case TYPE_DECIM: name = "DECIMAL"; break;
  136. case TYPE_BIN: name = "BINARY"; break;
  137. case TYPE_PCHAR: name = "PCHAR"; break;
  138. default: name = "UNKNOWN"; break;
  139. } // endswitch type
  140. return name;
  141. } // end of GetTypeName
  142. /***********************************************************************/
  143. /* GetTypeSize: returns the PlugDB internal type size. */
  144. /***********************************************************************/
  145. int GetTypeSize(int type, int len)
  146. {
  147. switch (type) {
  148. case TYPE_DECIM:
  149. case TYPE_BIN:
  150. case TYPE_STRING: len = len * sizeof(char); break;
  151. case TYPE_SHORT: len = sizeof(short); break;
  152. case TYPE_INT: len = sizeof(int); break;
  153. case TYPE_BIGINT: len = sizeof(longlong); break;
  154. case TYPE_DATE: len = sizeof(int); break;
  155. case TYPE_DOUBLE: len = sizeof(double); break;
  156. case TYPE_TINY: len = sizeof(char); break;
  157. case TYPE_PCHAR: len = sizeof(char*); break;
  158. default: len = 0;
  159. } // endswitch type
  160. return len;
  161. } // end of GetTypeSize
  162. /***********************************************************************/
  163. /* GetFormatType: returns the FORMAT character(s) according to type. */
  164. /***********************************************************************/
  165. char *GetFormatType(int type)
  166. {
  167. char *c = "X";
  168. switch (type) {
  169. case TYPE_STRING: c = "C"; break;
  170. case TYPE_SHORT: c = "S"; break;
  171. case TYPE_INT: c = "N"; break;
  172. case TYPE_BIGINT: c = "L"; break;
  173. case TYPE_DOUBLE: c = "F"; break;
  174. case TYPE_DATE: c = "D"; break;
  175. case TYPE_TINY: c = "T"; break;
  176. case TYPE_DECIM: c = "M"; break;
  177. case TYPE_BIN: c = "B"; break;
  178. case TYPE_PCHAR: c = "P"; break;
  179. } // endswitch type
  180. return c;
  181. } // end of GetFormatType
  182. /***********************************************************************/
  183. /* GetFormatType: returns the FORMAT type according to character. */
  184. /***********************************************************************/
  185. int GetFormatType(char c)
  186. {
  187. int type = TYPE_ERROR;
  188. switch (c) {
  189. case 'C': type = TYPE_STRING; break;
  190. case 'S': type = TYPE_SHORT; break;
  191. case 'N': type = TYPE_INT; break;
  192. case 'L': type = TYPE_BIGINT; break;
  193. case 'F': type = TYPE_DOUBLE; break;
  194. case 'D': type = TYPE_DATE; break;
  195. case 'T': type = TYPE_TINY; break;
  196. case 'M': type = TYPE_DECIM; break;
  197. case 'B': type = TYPE_BIN; break;
  198. case 'P': type = TYPE_PCHAR; break;
  199. } // endswitch type
  200. return type;
  201. } // end of GetFormatType
  202. /***********************************************************************/
  203. /* IsTypeChar: returns true for character type(s). */
  204. /***********************************************************************/
  205. bool IsTypeChar(int type)
  206. {
  207. switch (type) {
  208. case TYPE_STRING:
  209. case TYPE_DECIM:
  210. return true;
  211. } // endswitch type
  212. return false;
  213. } // end of IsTypeChar
  214. /***********************************************************************/
  215. /* IsTypeNum: returns true for numeric types. */
  216. /***********************************************************************/
  217. bool IsTypeNum(int type)
  218. {
  219. switch (type) {
  220. case TYPE_INT:
  221. case TYPE_BIGINT:
  222. case TYPE_DATE:
  223. case TYPE_DOUBLE:
  224. case TYPE_SHORT:
  225. case TYPE_NUM:
  226. case TYPE_TINY:
  227. case TYPE_DECIM:
  228. return true;
  229. } // endswitch type
  230. return false;
  231. } // end of IsTypeNum
  232. /***********************************************************************/
  233. /* GetFmt: returns the format to use with a typed value. */
  234. /***********************************************************************/
  235. const char *GetFmt(int type, bool un)
  236. {
  237. const char *fmt;
  238. switch (type) {
  239. case TYPE_DECIM:
  240. case TYPE_STRING: fmt = "%s"; break;
  241. case TYPE_SHORT: fmt = (un) ? "%hu" : "%hd"; break;
  242. case TYPE_BIGINT: fmt = (un) ? "%llu" : "%lld"; break;
  243. case TYPE_DOUBLE: fmt = "%.*lf"; break;
  244. case TYPE_BIN: fmt = "%*x"; break;
  245. default: fmt = (un) ? "%u" : "%d"; break;
  246. } // endswitch Type
  247. return fmt;
  248. } // end of GetFmt
  249. /***********************************************************************/
  250. /* ConvertType: what this function does is to determine the type to */
  251. /* which should be converted a value so no precision would be lost. */
  252. /* This can be a numeric type if num is true or non numeric if false. */
  253. /* Note: this is an ultra simplified version of this function that */
  254. /* should become more and more complex as new types are added. */
  255. /* Not evaluated types (TYPE_VOID or TYPE_UNDEF) return false from */
  256. /* IsType... functions so match does not prevent correct setting. */
  257. /***********************************************************************/
  258. int ConvertType(int target, int type, CONV kind, bool match)
  259. {
  260. switch (kind) {
  261. case CNV_CHAR:
  262. if (match && (!IsTypeChar(target) || !IsTypeChar(type)))
  263. return TYPE_ERROR;
  264. return TYPE_STRING;
  265. case CNV_NUM:
  266. if (match && (!IsTypeNum(target) || !IsTypeNum(type)))
  267. return TYPE_ERROR;
  268. return (target == TYPE_DOUBLE || type == TYPE_DOUBLE) ? TYPE_DOUBLE
  269. : (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE
  270. : (target == TYPE_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
  271. : (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
  272. : (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
  273. : TYPE_TINY;
  274. default:
  275. if (target == TYPE_ERROR || target == type)
  276. return type;
  277. if (match && ((IsTypeChar(target) && !IsTypeChar(type)) ||
  278. (IsTypeNum(target) && !IsTypeNum(type))))
  279. return TYPE_ERROR;
  280. return (target == TYPE_DOUBLE || type == TYPE_DOUBLE) ? TYPE_DOUBLE
  281. : (target == TYPE_DATE || type == TYPE_DATE) ? TYPE_DATE
  282. : (target == TYPE_BIGINT || type == TYPE_BIGINT) ? TYPE_BIGINT
  283. : (target == TYPE_INT || type == TYPE_INT) ? TYPE_INT
  284. : (target == TYPE_SHORT || type == TYPE_SHORT) ? TYPE_SHORT
  285. : (target == TYPE_STRING || type == TYPE_STRING) ? TYPE_STRING
  286. : (target == TYPE_TINY || type == TYPE_TINY) ? TYPE_TINY
  287. : TYPE_ERROR;
  288. } // endswitch kind
  289. } // end of ConvertType
  290. /***********************************************************************/
  291. /* AllocateConstant: allocates a constant Value. */
  292. /***********************************************************************/
  293. PVAL AllocateValue(PGLOBAL g, void *value, short type, short prec)
  294. {
  295. PVAL valp;
  296. if (trace)
  297. htrc("AllocateConstant: value=%p type=%hd\n", value, type);
  298. switch (type) {
  299. case TYPE_STRING:
  300. valp = new(g) TYPVAL<PSZ>((PSZ)value, prec);
  301. break;
  302. case TYPE_SHORT:
  303. valp = new(g) TYPVAL<short>(*(short*)value, TYPE_SHORT);
  304. break;
  305. case TYPE_INT:
  306. valp = new(g) TYPVAL<int>(*(int*)value, TYPE_INT);
  307. break;
  308. case TYPE_BIGINT:
  309. valp = new(g) TYPVAL<longlong>(*(longlong*)value, TYPE_BIGINT);
  310. break;
  311. case TYPE_DOUBLE:
  312. valp = new(g) TYPVAL<double>(*(double *)value, TYPE_DOUBLE, prec);
  313. break;
  314. case TYPE_TINY:
  315. valp = new(g) TYPVAL<char>(*(char *)value, TYPE_TINY);
  316. break;
  317. default:
  318. sprintf(g->Message, MSG(BAD_VALUE_TYPE), type);
  319. return NULL;
  320. } // endswitch Type
  321. valp->SetGlobal(g);
  322. return valp;
  323. } // end of AllocateValue
  324. /***********************************************************************/
  325. /* Allocate a variable Value according to type, length and precision. */
  326. /***********************************************************************/
  327. PVAL AllocateValue(PGLOBAL g, int type, int len, int prec,
  328. bool uns, PSZ fmt)
  329. {
  330. PVAL valp;
  331. switch (type) {
  332. case TYPE_STRING:
  333. valp = new(g) TYPVAL<PSZ>(g, (PSZ)NULL, len, prec);
  334. break;
  335. case TYPE_DATE:
  336. valp = new(g) DTVAL(g, len, prec, fmt);
  337. break;
  338. case TYPE_INT:
  339. if (uns)
  340. valp = new(g) TYPVAL<uint>((uint)0, TYPE_INT, 0, true);
  341. else
  342. valp = new(g) TYPVAL<int>((int)0, TYPE_INT);
  343. break;
  344. case TYPE_BIGINT:
  345. if (uns)
  346. valp = new(g) TYPVAL<ulonglong>((ulonglong)0, TYPE_BIGINT, 0, true);
  347. else
  348. valp = new(g) TYPVAL<longlong>((longlong)0, TYPE_BIGINT);
  349. break;
  350. case TYPE_SHORT:
  351. if (uns)
  352. valp = new(g) TYPVAL<ushort>((ushort)0, TYPE_SHORT, 0, true);
  353. else
  354. valp = new(g) TYPVAL<short>((short)0, TYPE_SHORT);
  355. break;
  356. case TYPE_DOUBLE:
  357. valp = new(g) TYPVAL<double>(0.0, TYPE_DOUBLE, prec);
  358. break;
  359. case TYPE_TINY:
  360. if (uns)
  361. valp = new(g) TYPVAL<uchar>((uchar)0, TYPE_TINY, 0, true);
  362. else
  363. valp = new(g) TYPVAL<char>((char)0, TYPE_TINY);
  364. break;
  365. case TYPE_DECIM:
  366. valp = new(g) DECVAL(g, (PSZ)NULL, len, prec, uns);
  367. break;
  368. case TYPE_BIN:
  369. valp = new(g) BINVAL(g, (void*)NULL, len, prec);
  370. break;
  371. default:
  372. sprintf(g->Message, MSG(BAD_VALUE_TYPE), type);
  373. return NULL;
  374. } // endswitch type
  375. valp->SetGlobal(g);
  376. return valp;
  377. } // end of AllocateValue
  378. /***********************************************************************/
  379. /* Allocate a constant Value converted to newtype. */
  380. /* Can also be used to copy a Value eventually converted. */
  381. /***********************************************************************/
  382. PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns)
  383. {
  384. PSZ p, sp;
  385. bool un = (uns < 0) ? false : (uns > 0) ? true : valp->IsUnsigned();
  386. PVAL vp;
  387. if (!valp)
  388. return NULL;
  389. if (newtype == TYPE_VOID) // Means allocate a value of the same type
  390. newtype = valp->GetType();
  391. switch (newtype) {
  392. case TYPE_STRING:
  393. p = (PSZ)PlugSubAlloc(g, NULL, 1 + valp->GetValLen());
  394. if ((sp = valp->GetCharString(p)) != p && sp)
  395. strcpy(p, sp);
  396. vp = new(g) TYPVAL<PSZ>(g, p, valp->GetValLen(), valp->GetValPrec());
  397. break;
  398. case TYPE_SHORT:
  399. if (un)
  400. vp = new(g) TYPVAL<ushort>(valp->GetUShortValue(),
  401. TYPE_SHORT, 0, true);
  402. else
  403. vp = new(g) TYPVAL<short>(valp->GetShortValue(), TYPE_SHORT);
  404. break;
  405. case TYPE_INT:
  406. if (un)
  407. vp = new(g) TYPVAL<uint>(valp->GetUIntValue(), TYPE_INT, 0, true);
  408. else
  409. vp = new(g) TYPVAL<int>(valp->GetIntValue(), TYPE_INT);
  410. break;
  411. case TYPE_BIGINT:
  412. if (un)
  413. vp = new(g) TYPVAL<ulonglong>(valp->GetUBigintValue(),
  414. TYPE_BIGINT, 0, true);
  415. else
  416. vp = new(g) TYPVAL<longlong>(valp->GetBigintValue(), TYPE_BIGINT);
  417. break;
  418. case TYPE_DATE:
  419. vp = new(g) DTVAL(valp->GetIntValue());
  420. break;
  421. case TYPE_DOUBLE:
  422. vp = new(g) TYPVAL<double>(valp->GetFloatValue(), TYPE_DOUBLE,
  423. (uns) ? uns : valp->GetValPrec());
  424. break;
  425. case TYPE_TINY:
  426. if (un)
  427. vp = new(g) TYPVAL<uchar>(valp->GetUTinyValue(),
  428. TYPE_TINY, 0, true);
  429. else
  430. vp = new(g) TYPVAL<char>(valp->GetTinyValue(), TYPE_TINY);
  431. break;
  432. default:
  433. sprintf(g->Message, MSG(BAD_VALUE_TYPE), newtype);
  434. return NULL;
  435. } // endswitch type
  436. vp->SetNullable(valp->GetNullable());
  437. vp->SetNull(valp->IsNull());
  438. vp->SetGlobal(g);
  439. return vp;
  440. } // end of AllocateValue
  441. /* -------------------------- Class VALUE ---------------------------- */
  442. /***********************************************************************/
  443. /* Class VALUE protected constructor. */
  444. /***********************************************************************/
  445. VALUE::VALUE(int type, bool un) : Type(type)
  446. {
  447. Null = false;
  448. Nullable = false;
  449. Unsigned = un;
  450. Clen = 0;
  451. Prec = 0;
  452. Fmt = GetFmt(Type, Unsigned);
  453. Xfmt = GetXfmt();
  454. } // end of VALUE constructor
  455. /***********************************************************************/
  456. /* VALUE GetXfmt: returns the extended format to use with typed value. */
  457. /***********************************************************************/
  458. const char *VALUE::GetXfmt(void)
  459. {
  460. const char *fmt;
  461. switch (Type) {
  462. case TYPE_DECIM:
  463. case TYPE_STRING: fmt = "%*s"; break;
  464. case TYPE_SHORT: fmt = (Unsigned) ? "%*hu" : "%*hd"; break;
  465. case TYPE_BIGINT: fmt = (Unsigned) ? "%*llu" : "%*lld"; break;
  466. case TYPE_DOUBLE: fmt = "%*.*lf"; break;
  467. case TYPE_BIN: fmt = "%*x"; break;
  468. default: fmt = (Unsigned) ? "%*u" : "%*d"; break;
  469. } // endswitch Type
  470. return fmt;
  471. } // end of GetFmt
  472. /***********************************************************************/
  473. /* Returns a BYTE indicating the comparison between two values. */
  474. /* Bit 1 indicates equality, Bit 2 less than, and Bit3 greater than. */
  475. /* More than 1 bit can be set only in the case of TYPE_LIST. */
  476. /***********************************************************************/
  477. BYTE VALUE::TestValue(PVAL vp)
  478. {
  479. int n = CompareValue(vp);
  480. return (n > 0) ? 0x04 : (n < 0) ? 0x02 : 0x01;
  481. } // end of TestValue
  482. /***********************************************************************/
  483. /* Compute a function on a string. */
  484. /***********************************************************************/
  485. bool VALUE::Compute(PGLOBAL g, PVAL *, int, OPVAL)
  486. {
  487. strcpy(g->Message, "Compute not implemented for this value type");
  488. return true;
  489. } // end of Compute
  490. /* -------------------------- Class TYPVAL ---------------------------- */
  491. /***********************************************************************/
  492. /* TYPVAL public constructor from a constant typed value. */
  493. /***********************************************************************/
  494. template <class TYPE>
  495. TYPVAL<TYPE>::TYPVAL(TYPE n, int type, int prec, bool un)
  496. : VALUE(type, un)
  497. {
  498. Tval = n;
  499. Clen = sizeof(TYPE);
  500. Prec = prec;
  501. } // end of TYPVAL constructor
  502. /***********************************************************************/
  503. /* Return unsigned max value for the type. */
  504. /***********************************************************************/
  505. template <class TYPE>
  506. ulonglong TYPVAL<TYPE>::MaxVal(void) {DBUG_ASSERT(false); return 0;}
  507. template <>
  508. ulonglong TYPVAL<short>::MaxVal(void) {return INT_MAX16;}
  509. template <>
  510. ulonglong TYPVAL<ushort>::MaxVal(void) {return UINT_MAX16;}
  511. template <>
  512. ulonglong TYPVAL<int>::MaxVal(void) {return INT_MAX32;}
  513. template <>
  514. ulonglong TYPVAL<uint>::MaxVal(void) {return UINT_MAX32;}
  515. template <>
  516. ulonglong TYPVAL<char>::MaxVal(void) {return INT_MAX8;}
  517. template <>
  518. ulonglong TYPVAL<uchar>::MaxVal(void) {return UINT_MAX8;}
  519. template <>
  520. ulonglong TYPVAL<longlong>::MaxVal(void) {return INT_MAX64;}
  521. template <>
  522. ulonglong TYPVAL<ulonglong>::MaxVal(void) {return ULONGLONG_MAX;}
  523. /***********************************************************************/
  524. /* TYPVAL GetValLen: returns the print length of the typed object. */
  525. /***********************************************************************/
  526. template <class TYPE>
  527. int TYPVAL<TYPE>::GetValLen(void)
  528. {
  529. char c[32];
  530. return sprintf(c, Fmt, Tval);
  531. } // end of GetValLen
  532. template <>
  533. int TYPVAL<double>::GetValLen(void)
  534. {
  535. char c[32];
  536. return sprintf(c, Fmt, Prec, Tval);
  537. } // end of GetValLen
  538. /***********************************************************************/
  539. /* TYPVAL SetValue: copy the value of another Value object. */
  540. /* This function allows conversion if chktype is false. */
  541. /***********************************************************************/
  542. template <class TYPE>
  543. bool TYPVAL<TYPE>::SetValue_pval(PVAL valp, bool chktype)
  544. {
  545. if (valp != this) {
  546. if (chktype && Type != valp->GetType())
  547. return true;
  548. if (!(Null = valp->IsNull() && Nullable))
  549. Tval = GetTypedValue(valp);
  550. else
  551. Reset();
  552. } // endif valp
  553. return false;
  554. } // end of SetValue
  555. template <>
  556. short TYPVAL<short>::GetTypedValue(PVAL valp)
  557. {return valp->GetShortValue();}
  558. template <>
  559. ushort TYPVAL<ushort>::GetTypedValue(PVAL valp)
  560. {return valp->GetUShortValue();}
  561. template <>
  562. int TYPVAL<int>::GetTypedValue(PVAL valp)
  563. {return valp->GetIntValue();}
  564. template <>
  565. uint TYPVAL<uint>::GetTypedValue(PVAL valp)
  566. {return valp->GetUIntValue();}
  567. template <>
  568. longlong TYPVAL<longlong>::GetTypedValue(PVAL valp)
  569. {return valp->GetBigintValue();}
  570. template <>
  571. ulonglong TYPVAL<ulonglong>::GetTypedValue(PVAL valp)
  572. {return valp->GetUBigintValue();}
  573. template <>
  574. double TYPVAL<double>::GetTypedValue(PVAL valp)
  575. {return valp->GetFloatValue();}
  576. template <>
  577. char TYPVAL<char>::GetTypedValue(PVAL valp)
  578. {return valp->GetTinyValue();}
  579. template <>
  580. uchar TYPVAL<uchar>::GetTypedValue(PVAL valp)
  581. {return valp->GetUTinyValue();}
  582. /***********************************************************************/
  583. /* TYPVAL SetValue: convert chars extracted from a line to TYPE value.*/
  584. /***********************************************************************/
  585. template <class TYPE>
  586. bool TYPVAL<TYPE>::SetValue_char(char *p, int n)
  587. {
  588. bool rc, minus;
  589. ulonglong maxval = MaxVal();
  590. ulonglong val = CharToNumber(p, n, maxval, Unsigned, &minus, &rc);
  591. if (minus && val < maxval)
  592. Tval = (TYPE)(-(signed)val);
  593. else
  594. Tval = (TYPE)val;
  595. if (trace > 1) {
  596. char buf[64];
  597. htrc(strcat(strcat(strcpy(buf, " setting %s to: "), Fmt), "\n"),
  598. GetTypeName(Type), Tval);
  599. } // endif trace
  600. Null = false;
  601. return rc;
  602. } // end of SetValue
  603. template <>
  604. bool TYPVAL<double>::SetValue_char(char *p, int n)
  605. {
  606. if (p && n > 0) {
  607. char buf[64];
  608. for (; n > 0 && *p == ' '; p++)
  609. n--;
  610. memcpy(buf, p, MY_MIN(n, 31));
  611. buf[n] = '\0';
  612. Tval = atof(buf);
  613. if (trace > 1)
  614. htrc(" setting double: '%s' -> %lf\n", buf, Tval);
  615. Null = false;
  616. } else {
  617. Reset();
  618. Null = Nullable;
  619. } // endif p
  620. return false;
  621. } // end of SetValue
  622. /***********************************************************************/
  623. /* TYPVAL SetValue: fill a typed value from a string. */
  624. /***********************************************************************/
  625. template <class TYPE>
  626. void TYPVAL<TYPE>::SetValue_psz(PSZ s)
  627. {
  628. if (s) {
  629. SetValue_char(s, (int)strlen(s));
  630. Null = false;
  631. } else {
  632. Reset();
  633. Null = Nullable;
  634. } // endif p
  635. } // end of SetValue
  636. /***********************************************************************/
  637. /* TYPVAL SetValue: set value with a TYPE extracted from a block. */
  638. /***********************************************************************/
  639. template <class TYPE>
  640. void TYPVAL<TYPE>::SetValue_pvblk(PVBLK blk, int n)
  641. {
  642. Tval = GetTypedValue(blk, n);
  643. Null = false;
  644. } // end of SetValue
  645. template <>
  646. int TYPVAL<int>::GetTypedValue(PVBLK blk, int n)
  647. {return blk->GetIntValue(n);}
  648. template <>
  649. uint TYPVAL<uint>::GetTypedValue(PVBLK blk, int n)
  650. {return blk->GetUIntValue(n);}
  651. template <>
  652. short TYPVAL<short>::GetTypedValue(PVBLK blk, int n)
  653. {return blk->GetShortValue(n);}
  654. template <>
  655. ushort TYPVAL<ushort>::GetTypedValue(PVBLK blk, int n)
  656. {return blk->GetUShortValue(n);}
  657. template <>
  658. longlong TYPVAL<longlong>::GetTypedValue(PVBLK blk, int n)
  659. {return blk->GetBigintValue(n);}
  660. template <>
  661. ulonglong TYPVAL<ulonglong>::GetTypedValue(PVBLK blk, int n)
  662. {return blk->GetUBigintValue(n);}
  663. template <>
  664. double TYPVAL<double>::GetTypedValue(PVBLK blk, int n)
  665. {return blk->GetFloatValue(n);}
  666. template <>
  667. char TYPVAL<char>::GetTypedValue(PVBLK blk, int n)
  668. {return blk->GetTinyValue(n);}
  669. template <>
  670. uchar TYPVAL<uchar>::GetTypedValue(PVBLK blk, int n)
  671. {return blk->GetUTinyValue(n);}
  672. /***********************************************************************/
  673. /* TYPVAL SetBinValue: with bytes extracted from a line. */
  674. /* Currently only used reading column of binary files. */
  675. /***********************************************************************/
  676. template <class TYPE>
  677. void TYPVAL<TYPE>::SetBinValue(void *p)
  678. {
  679. #if defined(UNALIGNED_OK)
  680. // x86 can cast non-aligned memory directly
  681. Tval = *(TYPE *)p;
  682. #else
  683. // Prevent unaligned memory access on MIPS and ArmHF platforms.
  684. // Make use of memcpy instead of straight pointer dereferencing.
  685. // Currently only used by WriteColumn of binary files.
  686. // From original author: Vicentiu Ciorbaru <vicentiu@mariadb.org>
  687. memcpy(&Tval, p, sizeof(TYPE));
  688. #endif
  689. Null = false;
  690. } // end of SetBinValue
  691. /***********************************************************************/
  692. /* GetBinValue: fill a buffer with the internal binary value. */
  693. /* This function checks whether the buffer length is enough and */
  694. /* returns true if not. Actual filling occurs only if go is true. */
  695. /* Currently only used writing column of binary files. */
  696. /***********************************************************************/
  697. template <class TYPE>
  698. bool TYPVAL<TYPE>::GetBinValue(void *buf, int buflen, bool go)
  699. {
  700. // Test on length was removed here until a variable in column give the
  701. // real field length. For BIN files the field length logically cannot
  702. // be different from the variable length because no conversion is done.
  703. // Therefore this test is useless anyway.
  704. //#if defined(_DEBUG)
  705. // if (sizeof(TYPE) > buflen)
  706. // return true;
  707. //#endif
  708. if (go)
  709. #if defined(UNALIGNED_OK)
  710. // x86 can cast non-aligned memory directly
  711. *(TYPE *)buf = Tval;
  712. #else
  713. // Prevent unaligned memory access on MIPS and ArmHF platforms.
  714. // Make use of memcpy instead of straight pointer dereferencing.
  715. // Currently only used by WriteColumn of binary files.
  716. // From original author: Vicentiu Ciorbaru <vicentiu@mariadb.org>
  717. memcpy(buf, &Tval, sizeof(TYPE));
  718. #endif
  719. Null = false;
  720. return false;
  721. } // end of GetBinValue
  722. /***********************************************************************/
  723. /* TYPVAL ShowValue: get string representation of a typed value. */
  724. /***********************************************************************/
  725. template <class TYPE>
  726. char *TYPVAL<TYPE>::ShowValue(char *buf, int len)
  727. {
  728. sprintf(buf, Xfmt, len, Tval);
  729. return buf;
  730. } // end of ShowValue
  731. template <>
  732. char *TYPVAL<double>::ShowValue(char *buf, int len)
  733. {
  734. // TODO: use snprintf to avoid possible overflow
  735. sprintf(buf, Xfmt, len, Prec, Tval);
  736. return buf;
  737. } // end of ShowValue
  738. /***********************************************************************/
  739. /* TYPVAL GetCharString: get string representation of a typed value. */
  740. /***********************************************************************/
  741. template <class TYPE>
  742. char *TYPVAL<TYPE>::GetCharString(char *p)
  743. {
  744. sprintf(p, Fmt, Tval);
  745. return p;
  746. } // end of GetCharString
  747. template <>
  748. char *TYPVAL<double>::GetCharString(char *p)
  749. {
  750. sprintf(p, Fmt, Prec, Tval);
  751. return p;
  752. } // end of GetCharString
  753. #if 0
  754. /***********************************************************************/
  755. /* TYPVAL GetShortString: get short representation of a typed value. */
  756. /***********************************************************************/
  757. template <class TYPE>
  758. char *TYPVAL<TYPE>::GetShortString(char *p, int n)
  759. {
  760. sprintf(p, "%*hd", n, (short)Tval);
  761. return p;
  762. } // end of GetShortString
  763. /***********************************************************************/
  764. /* TYPVAL GetIntString: get int representation of a typed value. */
  765. /***********************************************************************/
  766. template <class TYPE>
  767. char *TYPVAL<TYPE>::GetIntString(char *p, int n)
  768. {
  769. sprintf(p, "%*d", n, (int)Tval);
  770. return p;
  771. } // end of GetIntString
  772. /***********************************************************************/
  773. /* TYPVAL GetBigintString: get big int representation of a TYPE value.*/
  774. /***********************************************************************/
  775. template <class TYPE>
  776. char *TYPVAL<TYPE>::GetBigintString(char *p, int n)
  777. {
  778. sprintf(p, "%*lld", n, (longlong)Tval);
  779. return p;
  780. } // end of GetBigintString
  781. /***********************************************************************/
  782. /* TYPVAL GetFloatString: get double representation of a typed value. */
  783. /***********************************************************************/
  784. template <class TYPE>
  785. char *TYPVAL<TYPE>::GetFloatString(char *p, int n, int prec)
  786. {
  787. sprintf(p, "%*.*lf", n, (prec < 0) ? 2 : prec, (double)Tval);
  788. return p;
  789. } // end of GetFloatString
  790. /***********************************************************************/
  791. /* TYPVAL GetTinyString: get char representation of a typed value. */
  792. /***********************************************************************/
  793. template <class TYPE>
  794. char *TYPVAL<TYPE>::GetTinyString(char *p, int n)
  795. {
  796. sprintf(p, "%*d", n, (int)(char)Tval);
  797. return p;
  798. } // end of GetIntString
  799. #endif // 0
  800. /***********************************************************************/
  801. /* TYPVAL compare value with another Value. */
  802. /***********************************************************************/
  803. template <class TYPE>
  804. bool TYPVAL<TYPE>::IsEqual(PVAL vp, bool chktype)
  805. {
  806. if (this == vp)
  807. return true;
  808. else if (chktype && Type != vp->GetType())
  809. return false;
  810. else if (chktype && Unsigned != vp->IsUnsigned())
  811. return false;
  812. else if (Null || vp->IsNull())
  813. return false;
  814. else
  815. return (Tval == GetTypedValue(vp));
  816. } // end of IsEqual
  817. /***********************************************************************/
  818. /* Compare values and returns 1, 0 or -1 according to comparison. */
  819. /* This function is used for evaluation of numeric filters. */
  820. /***********************************************************************/
  821. template <class TYPE>
  822. int TYPVAL<TYPE>::CompareValue(PVAL vp)
  823. {
  824. //assert(vp->GetType() == Type);
  825. // Process filtering on numeric values.
  826. TYPE n = GetTypedValue(vp);
  827. //if (trace)
  828. // htrc(" Comparing: val=%d,%d\n", Tval, n);
  829. return (Tval > n) ? 1 : (Tval < n) ? (-1) : 0;
  830. } // end of CompareValue
  831. /***********************************************************************/
  832. /* Return max type value if b is true, else min type value. */
  833. /***********************************************************************/
  834. template <>
  835. short TYPVAL<short>::MinMaxVal(bool b)
  836. {return (b) ? INT_MAX16 : INT_MIN16;}
  837. template <>
  838. ushort TYPVAL<ushort>::MinMaxVal(bool b)
  839. {return (b) ? UINT_MAX16 : 0;}
  840. template <>
  841. int TYPVAL<int>::MinMaxVal(bool b)
  842. {return (b) ? INT_MAX32 : INT_MIN32;}
  843. template <>
  844. uint TYPVAL<uint>::MinMaxVal(bool b)
  845. {return (b) ? UINT_MAX32 : 0;}
  846. template <>
  847. longlong TYPVAL<longlong>::MinMaxVal(bool b)
  848. {return (b) ? INT_MAX64 : INT_MIN64;}
  849. template <>
  850. ulonglong TYPVAL<ulonglong>::MinMaxVal(bool b)
  851. {return (b) ? 0xFFFFFFFFFFFFFFFFLL : 0;}
  852. template <>
  853. double TYPVAL<double>::MinMaxVal(bool)
  854. {assert(false); return 0.0;}
  855. template <>
  856. char TYPVAL<char>::MinMaxVal(bool b)
  857. {return (b) ? INT_MAX8 : INT_MIN8;}
  858. template <>
  859. uchar TYPVAL<uchar>::MinMaxVal(bool b)
  860. {return (b) ? UINT_MAX8 : 0;}
  861. /***********************************************************************/
  862. /* SafeAdd: adds a value and test whether overflow/underflow occurred. */
  863. /***********************************************************************/
  864. template <class TYPE>
  865. TYPE TYPVAL<TYPE>::SafeAdd(TYPE n1, TYPE n2)
  866. {
  867. PGLOBAL& g = Global;
  868. TYPE n = n1 + n2;
  869. if ((n2 > 0) && (n < n1)) {
  870. // Overflow
  871. strcpy(g->Message, MSG(FIX_OVFLW_ADD));
  872. longjmp(g->jumper[g->jump_level], 138);
  873. } else if ((n2 < 0) && (n > n1)) {
  874. // Underflow
  875. strcpy(g->Message, MSG(FIX_UNFLW_ADD));
  876. longjmp(g->jumper[g->jump_level], 138);
  877. } // endif's n2
  878. return n;
  879. } // end of SafeAdd
  880. template <>
  881. inline double TYPVAL<double>::SafeAdd(double n1, double n2)
  882. {
  883. return n1 + n2;
  884. } // end of SafeAdd
  885. /***********************************************************************/
  886. /* SafeMult: multiply values and test whether overflow occurred. */
  887. /***********************************************************************/
  888. template <class TYPE>
  889. TYPE TYPVAL<TYPE>::SafeMult(TYPE n1, TYPE n2)
  890. {
  891. PGLOBAL& g = Global;
  892. double n = (double)n1 * (double)n2;
  893. if (n > MinMaxVal(true)) {
  894. // Overflow
  895. strcpy(g->Message, MSG(FIX_OVFLW_TIMES));
  896. longjmp(g->jumper[g->jump_level], 138);
  897. } else if (n < MinMaxVal(false)) {
  898. // Underflow
  899. strcpy(g->Message, MSG(FIX_UNFLW_TIMES));
  900. longjmp(g->jumper[g->jump_level], 138);
  901. } // endif's n2
  902. return (TYPE)n;
  903. } // end of SafeMult
  904. template <>
  905. inline double TYPVAL<double>::SafeMult(double n1, double n2)
  906. {
  907. return n1 * n2;
  908. } // end of SafeMult
  909. /***********************************************************************/
  910. /* Compute defined functions for the type. */
  911. /***********************************************************************/
  912. template <class TYPE>
  913. bool TYPVAL<TYPE>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
  914. {
  915. bool rc = false;
  916. TYPE val[2];
  917. assert(np == 2);
  918. for (int i = 0; i < np; i++)
  919. val[i] = GetTypedValue(vp[i]);
  920. switch (op) {
  921. case OP_ADD:
  922. Tval = SafeAdd(val[0], val[1]);
  923. break;
  924. case OP_MULT:
  925. Tval = SafeMult(val[0], val[1]);
  926. break;
  927. case OP_DIV:
  928. if (!val[1]) {
  929. strcpy(g->Message, MSG(ZERO_DIVIDE));
  930. return true;
  931. } // endif
  932. Tval = val[0] / val[1];
  933. break;
  934. default:
  935. rc = Compall(g, vp, np, op);
  936. break;
  937. } // endswitch op
  938. return rc;
  939. } // end of Compute
  940. template <>
  941. bool TYPVAL<double>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
  942. {
  943. bool rc = false;
  944. double val[2];
  945. assert(np == 2);
  946. for (int i = 0; i < np; i++)
  947. val[i] = vp[i]->GetFloatValue();
  948. switch (op) {
  949. case OP_ADD:
  950. Tval = val[0] + val[1];
  951. break;
  952. case OP_MULT:
  953. Tval = val[0] * val[1];
  954. break;
  955. default:
  956. rc = Compall(g, vp, np, op);
  957. } // endswitch op
  958. return rc;
  959. } // end of Compute
  960. /***********************************************************************/
  961. /* Compute a function for all types. */
  962. /***********************************************************************/
  963. template <class TYPE>
  964. bool TYPVAL<TYPE>::Compall(PGLOBAL g, PVAL *vp, int np, OPVAL op)
  965. {
  966. TYPE val[2];
  967. for (int i = 0; i < np; i++)
  968. val[i] = GetTypedValue(vp[i]);
  969. switch (op) {
  970. case OP_DIV:
  971. if (val[0]) {
  972. if (!val[1]) {
  973. strcpy(g->Message, MSG(ZERO_DIVIDE));
  974. return true;
  975. } // endif
  976. Tval = val[0] / val[1];
  977. } else
  978. Tval = 0;
  979. break;
  980. case OP_MIN:
  981. Tval = MY_MIN(val[0], val[1]);
  982. break;
  983. case OP_MAX:
  984. Tval = MY_MAX(val[0], val[1]);
  985. break;
  986. default:
  987. // sprintf(g->Message, MSG(BAD_EXP_OPER), op);
  988. strcpy(g->Message, "Function not supported");
  989. return true;
  990. } // endswitch op
  991. return false;
  992. } // end of Compall
  993. /***********************************************************************/
  994. /* FormatValue: This function set vp (a STRING value) to the string */
  995. /* constructed from its own value formated using the fmt format. */
  996. /* This function assumes that the format matches the value type. */
  997. /***********************************************************************/
  998. template <class TYPE>
  999. bool TYPVAL<TYPE>::FormatValue(PVAL vp, char *fmt)
  1000. {
  1001. char *buf = (char*)vp->GetTo_Val(); // Should be big enough
  1002. int n = sprintf(buf, fmt, Tval);
  1003. return (n > vp->GetValLen());
  1004. } // end of FormatValue
  1005. /***********************************************************************/
  1006. /* TYPVAL SetFormat function (used to set SELECT output format). */
  1007. /***********************************************************************/
  1008. template <class TYPE>
  1009. bool TYPVAL<TYPE>::SetConstFormat(PGLOBAL g, FORMAT& fmt)
  1010. {
  1011. char c[32];
  1012. fmt.Type[0] = *GetFormatType(Type);
  1013. fmt.Length = sprintf(c, Fmt, Tval);
  1014. fmt.Prec = Prec;
  1015. return false;
  1016. } // end of SetConstFormat
  1017. /***********************************************************************/
  1018. /* Make file output of a typed object. */
  1019. /***********************************************************************/
  1020. template <class TYPE>
  1021. void TYPVAL<TYPE>::Print(PGLOBAL g, FILE *f, uint n)
  1022. {
  1023. char m[64], buf[12];
  1024. memset(m, ' ', n); /* Make margin string */
  1025. m[n] = '\0';
  1026. if (Null)
  1027. fprintf(f, "%s<null>\n", m);
  1028. else
  1029. fprintf(f, strcat(strcat(strcpy(buf, "%s"), Fmt), "\n"), m, Tval);
  1030. } /* end of Print */
  1031. /***********************************************************************/
  1032. /* Make string output of a int object. */
  1033. /***********************************************************************/
  1034. template <class TYPE>
  1035. void TYPVAL<TYPE>::Print(PGLOBAL g, char *ps, uint z)
  1036. {
  1037. if (Null)
  1038. strcpy(ps, "<null>");
  1039. else
  1040. sprintf(ps, Fmt, Tval);
  1041. } /* end of Print */
  1042. /* -------------------------- Class STRING --------------------------- */
  1043. /***********************************************************************/
  1044. /* STRING public constructor from a constant string. */
  1045. /***********************************************************************/
  1046. TYPVAL<PSZ>::TYPVAL(PSZ s, short c) : VALUE(TYPE_STRING)
  1047. {
  1048. Strp = s;
  1049. Len = strlen(s);
  1050. Clen = Len;
  1051. Ci = (c == 1);
  1052. } // end of STRING constructor
  1053. /***********************************************************************/
  1054. /* STRING public constructor from char. */
  1055. /***********************************************************************/
  1056. TYPVAL<PSZ>::TYPVAL(PGLOBAL g, PSZ s, int n, int c)
  1057. : VALUE(TYPE_STRING)
  1058. {
  1059. Len = (g) ? n : (s) ? strlen(s) : 0;
  1060. if (!s) {
  1061. if (g) {
  1062. if ((Strp = (char *)PlgDBSubAlloc(g, NULL, Len + 1)))
  1063. memset(Strp, 0, Len + 1);
  1064. else
  1065. Len = 0;
  1066. } else
  1067. assert(false);
  1068. } else
  1069. Strp = s;
  1070. Clen = Len;
  1071. Ci = (c != 0);
  1072. } // end of STRING constructor
  1073. /***********************************************************************/
  1074. /* Get the tiny value represented by the Strp string. */
  1075. /***********************************************************************/
  1076. char TYPVAL<PSZ>::GetTinyValue(void)
  1077. {
  1078. bool m;
  1079. ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX8, false, &m);
  1080. return (m && val < INT_MAX8) ? (char)(-(signed)val) : (char)val;
  1081. } // end of GetTinyValue
  1082. /***********************************************************************/
  1083. /* Get the unsigned tiny value represented by the Strp string. */
  1084. /***********************************************************************/
  1085. uchar TYPVAL<PSZ>::GetUTinyValue(void)
  1086. {
  1087. return (uchar)CharToNumber(Strp, strlen(Strp), UINT_MAX8, true);
  1088. } // end of GetUTinyValue
  1089. /***********************************************************************/
  1090. /* Get the short value represented by the Strp string. */
  1091. /***********************************************************************/
  1092. short TYPVAL<PSZ>::GetShortValue(void)
  1093. {
  1094. bool m;
  1095. ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX16, false, &m);
  1096. return (m && val < INT_MAX16) ? (short)(-(signed)val) : (short)val;
  1097. } // end of GetShortValue
  1098. /***********************************************************************/
  1099. /* Get the unsigned short value represented by the Strp string. */
  1100. /***********************************************************************/
  1101. ushort TYPVAL<PSZ>::GetUShortValue(void)
  1102. {
  1103. return (ushort)CharToNumber(Strp, strlen(Strp), UINT_MAX16, true);
  1104. } // end of GetUshortValue
  1105. /***********************************************************************/
  1106. /* Get the integer value represented by the Strp string. */
  1107. /***********************************************************************/
  1108. int TYPVAL<PSZ>::GetIntValue(void)
  1109. {
  1110. bool m;
  1111. ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX32, false, &m);
  1112. return (m && val < INT_MAX32) ? (int)(-(signed)val) : (int)val;
  1113. } // end of GetIntValue
  1114. /***********************************************************************/
  1115. /* Get the unsigned integer value represented by the Strp string. */
  1116. /***********************************************************************/
  1117. uint TYPVAL<PSZ>::GetUIntValue(void)
  1118. {
  1119. return (uint)CharToNumber(Strp, strlen(Strp), UINT_MAX32, true);
  1120. } // end of GetUintValue
  1121. /***********************************************************************/
  1122. /* Get the big integer value represented by the Strp string. */
  1123. /***********************************************************************/
  1124. longlong TYPVAL<PSZ>::GetBigintValue(void)
  1125. {
  1126. bool m;
  1127. ulonglong val = CharToNumber(Strp, strlen(Strp), INT_MAX64, false, &m);
  1128. return (m && val < INT_MAX64) ? (-(signed)val) : (longlong)val;
  1129. } // end of GetBigintValue
  1130. /***********************************************************************/
  1131. /* Get the unsigned big integer value represented by the Strp string. */
  1132. /***********************************************************************/
  1133. ulonglong TYPVAL<PSZ>::GetUBigintValue(void)
  1134. {
  1135. return CharToNumber(Strp, strlen(Strp), ULONGLONG_MAX, true);
  1136. } // end of GetUBigintValue
  1137. /***********************************************************************/
  1138. /* STRING SetValue: copy the value of another Value object. */
  1139. /***********************************************************************/
  1140. bool TYPVAL<PSZ>::SetValue_pval(PVAL valp, bool chktype)
  1141. {
  1142. if (valp != this) {
  1143. if (chktype && (valp->GetType() != Type || valp->GetSize() > Len))
  1144. return true;
  1145. char buf[64];
  1146. if (!(Null = valp->IsNull() && Nullable))
  1147. strncpy(Strp, valp->GetCharString(buf), Len);
  1148. else
  1149. Reset();
  1150. } // endif valp
  1151. return false;
  1152. } // end of SetValue_pval
  1153. /***********************************************************************/
  1154. /* STRING SetValue: fill string with chars extracted from a line. */
  1155. /***********************************************************************/
  1156. bool TYPVAL<PSZ>::SetValue_char(char *p, int n)
  1157. {
  1158. bool rc = false;
  1159. if (!p || n == 0) {
  1160. Reset();
  1161. Null = Nullable;
  1162. } else if (p != Strp) {
  1163. rc = n > Len;
  1164. if ((n = MY_MIN(n, Len))) {
  1165. strncpy(Strp, p, n);
  1166. // for (p = Strp + n - 1; p >= Strp && (*p == ' ' || *p == '\0'); p--) ;
  1167. for (p = Strp + n - 1; p >= Strp; p--)
  1168. if (*p && *p != ' ')
  1169. break;
  1170. *(++p) = '\0';
  1171. if (trace > 1)
  1172. htrc(" Setting string to: '%s'\n", Strp);
  1173. } else
  1174. Reset();
  1175. Null = false;
  1176. } // endif p
  1177. return rc;
  1178. } // end of SetValue_char
  1179. /***********************************************************************/
  1180. /* STRING SetValue: fill string with another string. */
  1181. /***********************************************************************/
  1182. void TYPVAL<PSZ>::SetValue_psz(PSZ s)
  1183. {
  1184. if (!s) {
  1185. Reset();
  1186. Null = Nullable;
  1187. } else if (s != Strp) {
  1188. strncpy(Strp, s, Len);
  1189. Null = false;
  1190. } // endif s
  1191. } // end of SetValue_psz
  1192. /***********************************************************************/
  1193. /* STRING SetValue: fill string with a string extracted from a block. */
  1194. /***********************************************************************/
  1195. void TYPVAL<PSZ>::SetValue_pvblk(PVBLK blk, int n)
  1196. {
  1197. // STRBLK's can return a NULL pointer
  1198. PSZ vp = blk->GetCharString(Strp, n);
  1199. if (vp != Strp)
  1200. SetValue_psz(vp);
  1201. } // end of SetValue_pvblk
  1202. /***********************************************************************/
  1203. /* STRING SetValue: get the character representation of an integer. */
  1204. /***********************************************************************/
  1205. void TYPVAL<PSZ>::SetValue(int n)
  1206. {
  1207. char buf[16];
  1208. PGLOBAL& g = Global;
  1209. int k = sprintf(buf, "%d", n);
  1210. if (k > Len) {
  1211. sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
  1212. longjmp(g->jumper[g->jump_level], 138);
  1213. } else
  1214. SetValue_psz(buf);
  1215. Null = false;
  1216. } // end of SetValue
  1217. /***********************************************************************/
  1218. /* STRING SetValue: get the character representation of an uint. */
  1219. /***********************************************************************/
  1220. void TYPVAL<PSZ>::SetValue(uint n)
  1221. {
  1222. char buf[16];
  1223. PGLOBAL& g = Global;
  1224. int k = sprintf(buf, "%u", n);
  1225. if (k > Len) {
  1226. sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
  1227. longjmp(g->jumper[g->jump_level], 138);
  1228. } else
  1229. SetValue_psz(buf);
  1230. Null = false;
  1231. } // end of SetValue
  1232. /***********************************************************************/
  1233. /* STRING SetValue: get the character representation of a short int. */
  1234. /***********************************************************************/
  1235. void TYPVAL<PSZ>::SetValue(short i)
  1236. {
  1237. SetValue((int)i);
  1238. Null = false;
  1239. } // end of SetValue
  1240. /***********************************************************************/
  1241. /* STRING SetValue: get the character representation of a ushort int. */
  1242. /***********************************************************************/
  1243. void TYPVAL<PSZ>::SetValue(ushort i)
  1244. {
  1245. SetValue((uint)i);
  1246. Null = false;
  1247. } // end of SetValue
  1248. /***********************************************************************/
  1249. /* STRING SetValue: get the character representation of a big integer.*/
  1250. /***********************************************************************/
  1251. void TYPVAL<PSZ>::SetValue(longlong n)
  1252. {
  1253. char buf[24];
  1254. PGLOBAL& g = Global;
  1255. int k = sprintf(buf, "%lld", n);
  1256. if (k > Len) {
  1257. sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
  1258. longjmp(g->jumper[g->jump_level], 138);
  1259. } else
  1260. SetValue_psz(buf);
  1261. Null = false;
  1262. } // end of SetValue
  1263. /***********************************************************************/
  1264. /* STRING SetValue: get the character representation of a big integer.*/
  1265. /***********************************************************************/
  1266. void TYPVAL<PSZ>::SetValue(ulonglong n)
  1267. {
  1268. char buf[24];
  1269. PGLOBAL& g = Global;
  1270. int k = sprintf(buf, "%llu", n);
  1271. if (k > Len) {
  1272. sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
  1273. longjmp(g->jumper[g->jump_level], 138);
  1274. } else
  1275. SetValue_psz(buf);
  1276. Null = false;
  1277. } // end of SetValue
  1278. /***********************************************************************/
  1279. /* STRING SetValue: get the character representation of a double. */
  1280. /***********************************************************************/
  1281. void TYPVAL<PSZ>::SetValue(double f)
  1282. {
  1283. char *p, buf[64];
  1284. PGLOBAL& g = Global;
  1285. int k = sprintf(buf, "%lf", f);
  1286. for (p = buf + k - 1; p >= buf; p--)
  1287. if (*p == '0') {
  1288. *p = 0;
  1289. k--;
  1290. } else
  1291. break;
  1292. if (k > Len) {
  1293. sprintf(g->Message, MSG(VALSTR_TOO_LONG), buf, Len);
  1294. longjmp(g->jumper[g->jump_level], 138);
  1295. } else
  1296. SetValue_psz(buf);
  1297. Null = false;
  1298. } // end of SetValue
  1299. /***********************************************************************/
  1300. /* STRING SetValue: get the character representation of a tiny int. */
  1301. /***********************************************************************/
  1302. void TYPVAL<PSZ>::SetValue(char c)
  1303. {
  1304. SetValue((int)c);
  1305. Null = false;
  1306. } // end of SetValue
  1307. /***********************************************************************/
  1308. /* STRING SetValue: get the character representation of a tiny int. */
  1309. /***********************************************************************/
  1310. void TYPVAL<PSZ>::SetValue(uchar c)
  1311. {
  1312. SetValue((uint)c);
  1313. Null = false;
  1314. } // end of SetValue
  1315. /***********************************************************************/
  1316. /* STRING SetBinValue: fill string with chars extracted from a line. */
  1317. /***********************************************************************/
  1318. void TYPVAL<PSZ>::SetBinValue(void *p)
  1319. {
  1320. SetValue_char((char *)p, Len);
  1321. } // end of SetBinValue
  1322. /***********************************************************************/
  1323. /* GetBinValue: fill a buffer with the internal binary value. */
  1324. /* This function checks whether the buffer length is enough and */
  1325. /* returns true if not. Actual filling occurs only if go is true. */
  1326. /* Currently used by WriteColumn of binary files. */
  1327. /***********************************************************************/
  1328. bool TYPVAL<PSZ>::GetBinValue(void *buf, int buflen, bool go)
  1329. {
  1330. int len = (Null) ? 0 : strlen(Strp);
  1331. if (len > buflen)
  1332. return true;
  1333. else if (go) {
  1334. memset(buf, ' ', buflen);
  1335. memcpy(buf, Strp, len);
  1336. } // endif go
  1337. return false;
  1338. } // end of GetBinValue
  1339. /***********************************************************************/
  1340. /* STRING ShowValue: get string representation of a char value. */
  1341. /***********************************************************************/
  1342. char *TYPVAL<PSZ>::ShowValue(char *, int)
  1343. {
  1344. return Strp;
  1345. } // end of ShowValue
  1346. /***********************************************************************/
  1347. /* STRING GetCharString: get string representation of a char value. */
  1348. /***********************************************************************/
  1349. char *TYPVAL<PSZ>::GetCharString(char *)
  1350. {
  1351. return Strp;
  1352. } // end of GetCharString
  1353. /***********************************************************************/
  1354. /* STRING compare value with another Value. */
  1355. /***********************************************************************/
  1356. bool TYPVAL<PSZ>::IsEqual(PVAL vp, bool chktype)
  1357. {
  1358. if (this == vp)
  1359. return true;
  1360. else if (chktype && Type != vp->GetType())
  1361. return false;
  1362. else if (Null || vp->IsNull())
  1363. return false;
  1364. char buf[64];
  1365. if (Ci || vp->IsCi())
  1366. return !stricmp(Strp, vp->GetCharString(buf));
  1367. else // (!Ci)
  1368. return !strcmp(Strp, vp->GetCharString(buf));
  1369. } // end of IsEqual
  1370. /***********************************************************************/
  1371. /* Compare values and returns 1, 0 or -1 according to comparison. */
  1372. /* This function is used for evaluation of numeric filters. */
  1373. /***********************************************************************/
  1374. int TYPVAL<PSZ>::CompareValue(PVAL vp)
  1375. {
  1376. int n;
  1377. //assert(vp->GetType() == Type);
  1378. if (trace)
  1379. htrc(" Comparing: val='%s','%s'\n", Strp, vp->GetCharValue());
  1380. // Process filtering on character strings.
  1381. if (Ci || vp->IsCi())
  1382. n = stricmp(Strp, vp->GetCharValue());
  1383. else
  1384. n = strcmp(Strp, vp->GetCharValue());
  1385. #if defined(__WIN__)
  1386. if (n == _NLSCMPERROR)
  1387. return n; // Here we should raise an error
  1388. #endif // __WIN__
  1389. return (n > 0) ? 1 : (n < 0) ? -1 : 0;
  1390. } // end of CompareValue
  1391. /***********************************************************************/
  1392. /* Compute a function on a string. */
  1393. /***********************************************************************/
  1394. bool TYPVAL<PSZ>::Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op)
  1395. {
  1396. char *p[2], val[2][32];
  1397. int i;
  1398. for (i = 0; i < np; i++)
  1399. p[i] = vp[i]->GetCharString(val[i]);
  1400. switch (op) {
  1401. case OP_CNC:
  1402. assert(np == 1 || np == 2);
  1403. if (np == 2)
  1404. SetValue_psz(p[0]);
  1405. if ((i = Len - (signed)strlen(Strp)) > 0)
  1406. strncat(Strp, p[np - 1], i);
  1407. break;
  1408. case OP_MIN:
  1409. assert(np == 2);
  1410. SetValue_psz((strcmp(p[0], p[1]) < 0) ? p[0] : p[1]);
  1411. break;
  1412. case OP_MAX:
  1413. assert(np == 2);
  1414. SetValue_psz((strcmp(p[0], p[1]) > 0) ? p[0] : p[1]);
  1415. break;
  1416. default:
  1417. // sprintf(g->Message, MSG(BAD_EXP_OPER), op);
  1418. strcpy(g->Message, "Function not supported");
  1419. return true;
  1420. } // endswitch op
  1421. return false;
  1422. } // end of Compute
  1423. /***********************************************************************/
  1424. /* FormatValue: This function set vp (a STRING value) to the string */
  1425. /* constructed from its own value formated using the fmt format. */
  1426. /* This function assumes that the format matches the value type. */
  1427. /***********************************************************************/
  1428. bool TYPVAL<PSZ>::FormatValue(PVAL vp, char *fmt)
  1429. {
  1430. char *buf = (char*)vp->GetTo_Val(); // Should be big enough
  1431. int n = sprintf(buf, fmt, Strp);
  1432. return (n > vp->GetValLen());
  1433. } // end of FormatValue
  1434. /***********************************************************************/
  1435. /* STRING SetFormat function (used to set SELECT output format). */
  1436. /***********************************************************************/
  1437. bool TYPVAL<PSZ>::SetConstFormat(PGLOBAL, FORMAT& fmt)
  1438. {
  1439. fmt.Type[0] = 'C';
  1440. fmt.Length = Len;
  1441. fmt.Prec = 0;
  1442. return false;
  1443. } // end of SetConstFormat
  1444. /* -------------------------- Class DECIMAL -------------------------- */
  1445. /***********************************************************************/
  1446. /* DECIMAL public constructor from a constant string. */
  1447. /***********************************************************************/
  1448. DECVAL::DECVAL(PSZ s) : TYPVAL<PSZ>(s)
  1449. {
  1450. if (s) {
  1451. char *p = strchr(Strp, '.');
  1452. Prec = (p) ? Len - (p - Strp) : 0;
  1453. } // endif s
  1454. Type = TYPE_DECIM;
  1455. } // end of DECVAL constructor
  1456. /***********************************************************************/
  1457. /* DECIMAL public constructor from char. */
  1458. /***********************************************************************/
  1459. DECVAL::DECVAL(PGLOBAL g, PSZ s, int n, int prec, bool uns)
  1460. : TYPVAL<PSZ>(g, s, n + (prec ? 1 : 0) + (uns ? 0 : 1), 0)
  1461. {
  1462. Prec = prec;
  1463. Unsigned = uns;
  1464. Type = TYPE_DECIM;
  1465. } // end of DECVAL constructor
  1466. /***********************************************************************/
  1467. /* DECIMAL: Check whether the numerica value is equal to 0. */
  1468. /***********************************************************************/
  1469. bool DECVAL::IsZero(void)
  1470. {
  1471. for (int i = 0; Strp[i]; i++)
  1472. if (!strchr("0 +-.", Strp[i]))
  1473. return false;
  1474. return true;
  1475. } // end of IsZero
  1476. /***********************************************************************/
  1477. /* DECIMAL: Reset value to zero. */
  1478. /***********************************************************************/
  1479. void DECVAL::Reset(void)
  1480. {
  1481. int i = 0;
  1482. Strp[i++] = '0';
  1483. if (Prec) {
  1484. Strp[i++] = '.';
  1485. do {
  1486. Strp[i++] = '0';
  1487. } while (i < Prec + 2);
  1488. } // endif Prec
  1489. Strp[i] = 0;
  1490. } // end of Reset
  1491. /***********************************************************************/
  1492. /* DECIMAL ShowValue: get string representation right justified. */
  1493. /***********************************************************************/
  1494. char *DECVAL::ShowValue(char *buf, int len)
  1495. {
  1496. sprintf(buf, Xfmt, len, Strp);
  1497. return buf;
  1498. } // end of ShowValue
  1499. /***********************************************************************/
  1500. /* GetBinValue: fill a buffer with the internal binary value. */
  1501. /* This function checks whether the buffer length is enough and */
  1502. /* returns true if not. Actual filling occurs only if go is true. */
  1503. /* Currently used by WriteColumn of binary files. */
  1504. /***********************************************************************/
  1505. bool DECVAL::GetBinValue(void *buf, int buflen, bool go)
  1506. {
  1507. int len = (Null) ? 0 : strlen(Strp);
  1508. if (len > buflen)
  1509. return true;
  1510. else if (go) {
  1511. memset(buf, ' ', buflen - len);
  1512. memcpy((char*)buf + buflen - len, Strp, len);
  1513. } // endif go
  1514. return false;
  1515. } // end of GetBinValue
  1516. #if 0
  1517. /***********************************************************************/
  1518. /* DECIMAL SetValue: copy the value of another Value object. */
  1519. /***********************************************************************/
  1520. bool DECVAL::SetValue_pval(PVAL valp, bool chktype)
  1521. {
  1522. if (chktype && (valp->GetType() != Type || valp->GetSize() > Len))
  1523. return true;
  1524. char buf[64];
  1525. if (!(Null = valp->IsNull() && Nullable))
  1526. strncpy(Strp, valp->GetCharString(buf), Len);
  1527. else
  1528. Reset();
  1529. return false;
  1530. } // end of SetValue_pval
  1531. /***********************************************************************/
  1532. /* DECIMAL SetValue: fill string with chars extracted from a line. */
  1533. /***********************************************************************/
  1534. bool DECVAL::SetValue_char(char *p, int n)
  1535. {
  1536. bool rc;
  1537. if (p && n > 0) {
  1538. rc = n > Len;
  1539. if ((n = MY_MIN(n, Len))) {
  1540. strncpy(Strp, p, n);
  1541. // for (p = Strp + n - 1; p >= Strp && (*p == ' ' || *p == '\0'); p--) ;
  1542. for (p = Strp + n - 1; p >= Strp; p--)
  1543. if (*p && *p != ' ')
  1544. break;
  1545. *(++p) = '\0';
  1546. if (trace > 1)
  1547. htrc(" Setting string to: '%s'\n", Strp);
  1548. } else
  1549. Reset();
  1550. Null = false;
  1551. } else {
  1552. rc = false;
  1553. Reset();
  1554. Null = Nullable;
  1555. } // endif p
  1556. return rc;
  1557. } // end of SetValue_char
  1558. /***********************************************************************/
  1559. /* DECIMAL SetValue: fill string with another string. */
  1560. /***********************************************************************/
  1561. void DECVAL::SetValue_psz(PSZ s)
  1562. {
  1563. if (s) {
  1564. strncpy(Strp, s, Len);
  1565. Null = false;
  1566. } else {
  1567. Reset();
  1568. Null = Nullable;
  1569. } // endif s
  1570. } // end of SetValue_psz
  1571. /***********************************************************************/
  1572. /* DECIMAL SetValue: fill string with a string extracted from a block.*/
  1573. /***********************************************************************/
  1574. void DECVAL::SetValue_pvblk(PVBLK blk, int n)
  1575. {
  1576. // STRBLK's can return a NULL pointer
  1577. SetValue_psz(blk->GetCharValue(n));
  1578. } // end of SetValue_pvblk
  1579. /***********************************************************************/
  1580. /* DECIMAL SetBinValue: fill string with chars extracted from a line. */
  1581. /***********************************************************************/
  1582. void DECVAL::SetBinValue(void *p)
  1583. {
  1584. SetValue_char((char *)p, Len);
  1585. } // end of SetBinValue
  1586. /***********************************************************************/
  1587. /* DECIMAL GetCharString: get string representation of a char value. */
  1588. /***********************************************************************/
  1589. char *DECVAL::GetCharString(char *p)
  1590. {
  1591. return Strp;
  1592. } // end of GetCharString
  1593. #endif // 0
  1594. /***********************************************************************/
  1595. /* DECIMAL compare value with another Value. */
  1596. /***********************************************************************/
  1597. bool DECVAL::IsEqual(PVAL vp, bool chktype)
  1598. {
  1599. if (this == vp)
  1600. return true;
  1601. else if (chktype && Type != vp->GetType())
  1602. return false;
  1603. else if (Null || vp->IsNull())
  1604. return false;
  1605. char buf[64];
  1606. return !strcmp(Strp, vp->GetCharString(buf));
  1607. } // end of IsEqual
  1608. /***********************************************************************/
  1609. /* Compare values and returns 1, 0 or -1 according to comparison. */
  1610. /* This function is used for evaluation of numeric filters. */
  1611. /***********************************************************************/
  1612. int DECVAL::CompareValue(PVAL vp)
  1613. {
  1614. //assert(vp->GetType() == Type);
  1615. // Process filtering on numeric values.
  1616. double f = atof(Strp), n = vp->GetFloatValue();
  1617. //if (trace)
  1618. // htrc(" Comparing: val=%d,%d\n", f, n);
  1619. return (f > n) ? 1 : (f < n) ? (-1) : 0;
  1620. } // end of CompareValue
  1621. #if 0
  1622. /***********************************************************************/
  1623. /* FormatValue: This function set vp (a STRING value) to the string */
  1624. /* constructed from its own value formated using the fmt format. */
  1625. /* This function assumes that the format matches the value type. */
  1626. /***********************************************************************/
  1627. bool DECVAL::FormatValue(PVAL vp, char *fmt)
  1628. {
  1629. char *buf = (char*)vp->GetTo_Val(); // Should be big enough
  1630. int n = sprintf(buf, fmt, Strp);
  1631. return (n > vp->GetValLen());
  1632. } // end of FormatValue
  1633. /***********************************************************************/
  1634. /* DECIMAL SetFormat function (used to set SELECT output format). */
  1635. /***********************************************************************/
  1636. bool DECVAL::SetConstFormat(PGLOBAL g, FORMAT& fmt)
  1637. {
  1638. fmt.Type[0] = 'C';
  1639. fmt.Length = Len;
  1640. fmt.Prec = 0;
  1641. return false;
  1642. } // end of SetConstFormat
  1643. #endif // 0
  1644. /* -------------------------- Class BINVAL --------------------------- */
  1645. /***********************************************************************/
  1646. /* BINVAL public constructor from bytes. */
  1647. /***********************************************************************/
  1648. BINVAL::BINVAL(PGLOBAL g, void *p, int cl, int n) : VALUE(TYPE_BIN)
  1649. {
  1650. assert(g);
  1651. Len = n;
  1652. Clen = cl;
  1653. Binp = PlugSubAlloc(g, NULL, Clen + 1);
  1654. memset(Binp, 0, Clen + 1);
  1655. if (p)
  1656. memcpy(Binp, p, Len);
  1657. Chrp = NULL;
  1658. } // end of BINVAL constructor
  1659. /***********************************************************************/
  1660. /* BINVAL: Check whether the hexadecimal value is equal to 0. */
  1661. /***********************************************************************/
  1662. bool BINVAL::IsZero(void)
  1663. {
  1664. for (int i = 0; i < Len; i++)
  1665. if (((char*)Binp)[i] != 0)
  1666. return false;
  1667. return true;
  1668. } // end of IsZero
  1669. /***********************************************************************/
  1670. /* BINVAL: Reset value to zero. */
  1671. /***********************************************************************/
  1672. void BINVAL::Reset(void)
  1673. {
  1674. memset(Binp, 0, Clen);
  1675. Len = 0;
  1676. } // end of Reset
  1677. /***********************************************************************/
  1678. /* Get the tiny value pointed by Binp. */
  1679. /***********************************************************************/
  1680. char BINVAL::GetTinyValue(void)
  1681. {
  1682. return *(char*)Binp;
  1683. } // end of GetTinyValue
  1684. /***********************************************************************/
  1685. /* Get the unsigned tiny value pointed by Binp. */
  1686. /***********************************************************************/
  1687. uchar BINVAL::GetUTinyValue(void)
  1688. {
  1689. return *(uchar*)Binp;
  1690. } // end of GetUTinyValue
  1691. /***********************************************************************/
  1692. /* Get the short value pointed by Binp. */
  1693. /***********************************************************************/
  1694. short BINVAL::GetShortValue(void)
  1695. {
  1696. if (Len >= 2)
  1697. return *(short*)Binp;
  1698. else
  1699. return (short)GetTinyValue();
  1700. } // end of GetShortValue
  1701. /***********************************************************************/
  1702. /* Get the unsigned short value pointed by Binp. */
  1703. /***********************************************************************/
  1704. ushort BINVAL::GetUShortValue(void)
  1705. {
  1706. return (ushort)GetShortValue();
  1707. } // end of GetUshortValue
  1708. /***********************************************************************/
  1709. /* Get the integer value pointed by Binp. */
  1710. /***********************************************************************/
  1711. int BINVAL::GetIntValue(void)
  1712. {
  1713. if (Len >= 4)
  1714. return *(int*)Binp;
  1715. else
  1716. return (int)GetShortValue();
  1717. } // end of GetIntValue
  1718. /***********************************************************************/
  1719. /* Get the unsigned integer value pointed by Binp. */
  1720. /***********************************************************************/
  1721. uint BINVAL::GetUIntValue(void)
  1722. {
  1723. return (uint)GetIntValue();
  1724. } // end of GetUintValue
  1725. /***********************************************************************/
  1726. /* Get the big integer value pointed by Binp. */
  1727. /***********************************************************************/
  1728. longlong BINVAL::GetBigintValue(void)
  1729. {
  1730. if (Len >= 8)
  1731. return *(longlong*)Binp;
  1732. else
  1733. return (longlong)GetIntValue();
  1734. } // end of GetBigintValue
  1735. /***********************************************************************/
  1736. /* Get the unsigned big integer value pointed by Binp. */
  1737. /***********************************************************************/
  1738. ulonglong BINVAL::GetUBigintValue(void)
  1739. {
  1740. return (ulonglong)GetBigintValue();
  1741. } // end of GetUBigintValue
  1742. /***********************************************************************/
  1743. /* Get the double value pointed by Binp. */
  1744. /***********************************************************************/
  1745. double BINVAL::GetFloatValue(void)
  1746. {
  1747. if (Len >= 8)
  1748. return *(double*)Binp;
  1749. else if (Len >= 4)
  1750. return (double)(*(float*)Binp);
  1751. else
  1752. return 0.0;
  1753. } // end of GetFloatValue
  1754. /***********************************************************************/
  1755. /* BINVAL SetValue: copy the value of another Value object. */
  1756. /***********************************************************************/
  1757. bool BINVAL::SetValue_pval(PVAL valp, bool chktype)
  1758. {
  1759. bool rc = false;
  1760. if (valp != this) {
  1761. if (chktype && (valp->GetType() != Type || valp->GetSize() > Clen))
  1762. return true;
  1763. if (!(Null = valp->IsNull() && Nullable)) {
  1764. if ((rc = (Len = valp->GetSize()) > Clen))
  1765. Len = Clen;
  1766. memcpy(Binp, valp->GetTo_Val(), Len);
  1767. } else
  1768. Reset();
  1769. } // endif valp
  1770. return rc;
  1771. } // end of SetValue_pval
  1772. /***********************************************************************/
  1773. /* BINVAL SetValue: fill value with chars extracted from a line. */
  1774. /***********************************************************************/
  1775. bool BINVAL::SetValue_char(char *p, int n)
  1776. {
  1777. bool rc;
  1778. if (p && n > 0) {
  1779. rc = n > Clen;
  1780. Len = MY_MIN(n, Clen);
  1781. memcpy(Binp, p, Len);
  1782. Null = false;
  1783. } else {
  1784. rc = false;
  1785. Reset();
  1786. Null = Nullable;
  1787. } // endif p
  1788. return rc;
  1789. } // end of SetValue_char
  1790. /***********************************************************************/
  1791. /* BINVAL SetValue: fill value with another string. */
  1792. /***********************************************************************/
  1793. void BINVAL::SetValue_psz(PSZ s)
  1794. {
  1795. if (s) {
  1796. Len = MY_MIN(Clen, (signed)strlen(s));
  1797. memcpy(Binp, s, Len);
  1798. Null = false;
  1799. } else {
  1800. Reset();
  1801. Null = Nullable;
  1802. } // endif s
  1803. } // end of SetValue_psz
  1804. /***********************************************************************/
  1805. /* BINVAL SetValue: fill value with bytes extracted from a block. */
  1806. /***********************************************************************/
  1807. void BINVAL::SetValue_pvblk(PVBLK blk, int n)
  1808. {
  1809. // STRBLK's can return a NULL pointer
  1810. void *vp = blk->GetValPtrEx(n);
  1811. if (!vp || blk->IsNull(n)) {
  1812. Reset();
  1813. Null = Nullable;
  1814. } else if (vp != Binp) {
  1815. if (blk->GetType() == TYPE_STRING)
  1816. Len = strlen((char*)vp);
  1817. else
  1818. Len = blk->GetVlen();
  1819. Len = MY_MIN(Clen, Len);
  1820. memcpy(Binp, vp, Len);
  1821. Null = false;
  1822. } // endif vp
  1823. } // end of SetValue_pvblk
  1824. /***********************************************************************/
  1825. /* BINVAL SetValue: get the binary representation of an integer. */
  1826. /***********************************************************************/
  1827. void BINVAL::SetValue(int n)
  1828. {
  1829. if (Clen >= 4) {
  1830. *((int*)Binp) = n;
  1831. Len = 4;
  1832. } else
  1833. SetValue((short)n);
  1834. } // end of SetValue
  1835. /***********************************************************************/
  1836. /* BINVAL SetValue: get the binary representation of an uint. */
  1837. /***********************************************************************/
  1838. void BINVAL::SetValue(uint n)
  1839. {
  1840. if (Clen >= 4) {
  1841. *((uint*)Binp) = n;
  1842. Len = 4;
  1843. } else
  1844. SetValue((ushort)n);
  1845. } // end of SetValue
  1846. /***********************************************************************/
  1847. /* BINVAL SetValue: get the binary representation of a short int. */
  1848. /***********************************************************************/
  1849. void BINVAL::SetValue(short i)
  1850. {
  1851. if (Clen >= 2) {
  1852. *((int*)Binp) = i;
  1853. Len = 2;
  1854. } else
  1855. SetValue((char)i);
  1856. } // end of SetValue
  1857. /***********************************************************************/
  1858. /* BINVAL SetValue: get the binary representation of a ushort int. */
  1859. /***********************************************************************/
  1860. void BINVAL::SetValue(ushort i)
  1861. {
  1862. if (Clen >= 2) {
  1863. *((uint*)Binp) = i;
  1864. Len = 2;
  1865. } else
  1866. SetValue((uchar)i);
  1867. } // end of SetValue
  1868. /***********************************************************************/
  1869. /* BINVAL SetValue: get the binary representation of a big integer. */
  1870. /***********************************************************************/
  1871. void BINVAL::SetValue(longlong n)
  1872. {
  1873. if (Clen >= 8) {
  1874. *((longlong*)Binp) = n;
  1875. Len = 8;
  1876. } else
  1877. SetValue((int)n);
  1878. } // end of SetValue
  1879. /***********************************************************************/
  1880. /* BINVAL SetValue: get the binary representation of a big integer. */
  1881. /***********************************************************************/
  1882. void BINVAL::SetValue(ulonglong n)
  1883. {
  1884. if (Clen >= 8) {
  1885. *((ulonglong*)Binp) = n;
  1886. Len = 8;
  1887. } else
  1888. SetValue((uint)n);
  1889. } // end of SetValue
  1890. /***********************************************************************/
  1891. /* BINVAL SetValue: get the binary representation of a double. */
  1892. /***********************************************************************/
  1893. void BINVAL::SetValue(double n)
  1894. {
  1895. if (Clen >= 8) {
  1896. *((double*)Binp) = n;
  1897. Len = 8;
  1898. } else if (Clen >= 4) {
  1899. *((float*)Binp) = (float)n;
  1900. Len = 4;
  1901. } else
  1902. Len = 0;
  1903. } // end of SetValue
  1904. /***********************************************************************/
  1905. /* BINVAL SetValue: get the character binary of a tiny int. */
  1906. /***********************************************************************/
  1907. void BINVAL::SetValue(char c)
  1908. {
  1909. *((char*)Binp) = c;
  1910. Len = 1;
  1911. } // end of SetValue
  1912. /***********************************************************************/
  1913. /* BINVAL SetValue: get the binary representation of a tiny int. */
  1914. /***********************************************************************/
  1915. void BINVAL::SetValue(uchar c)
  1916. {
  1917. *((uchar*)Binp) = c;
  1918. Len = 1;
  1919. } // end of SetValue
  1920. /***********************************************************************/
  1921. /* BINVAL SetBinValue: fill string with bytes extracted from a line. */
  1922. /***********************************************************************/
  1923. void BINVAL::SetBinValue(void *p)
  1924. {
  1925. memcpy(Binp, p, Clen);
  1926. } // end of SetBinValue
  1927. /***********************************************************************/
  1928. /* GetBinValue: fill a buffer with the internal binary value. */
  1929. /* This function checks whether the buffer length is enough and */
  1930. /* returns true if not. Actual filling occurs only if go is true. */
  1931. /* Currently used by WriteColumn of binary files. */
  1932. /***********************************************************************/
  1933. bool BINVAL::GetBinValue(void *buf, int buflen, bool go)
  1934. {
  1935. if (Len > buflen)
  1936. return true;
  1937. else if (go) {
  1938. memset(buf, 0, buflen);
  1939. memcpy(buf, Binp, Len);
  1940. } // endif go
  1941. return false;
  1942. } // end of GetBinValue
  1943. /***********************************************************************/
  1944. /* BINVAL ShowValue: get string representation of a binary value. */
  1945. /***********************************************************************/
  1946. char *BINVAL::ShowValue(char *buf, int len)
  1947. {
  1948. int n = MY_MIN(Len, len / 2);
  1949. sprintf(buf, GetXfmt(), n, Binp);
  1950. return buf;
  1951. } // end of ShowValue
  1952. /***********************************************************************/
  1953. /* BINVAL GetCharString: get string representation of a binary value. */
  1954. /***********************************************************************/
  1955. char *BINVAL::GetCharString(char *)
  1956. {
  1957. if (!Chrp)
  1958. Chrp = (char*)PlugSubAlloc(Global, NULL, Clen * 2 + 1);
  1959. sprintf(Chrp, GetXfmt(), Len, Binp);
  1960. return Chrp;
  1961. } // end of GetCharString
  1962. /***********************************************************************/
  1963. /* BINVAL compare value with another Value. */
  1964. /***********************************************************************/
  1965. bool BINVAL::IsEqual(PVAL vp, bool chktype)
  1966. {
  1967. if (this == vp)
  1968. return true;
  1969. else if (chktype && Type != vp->GetType())
  1970. return false;
  1971. else if (Null || vp->IsNull())
  1972. return false;
  1973. else if (Len != vp->GetSize())
  1974. return false;
  1975. char *v1 = (char*)Binp;
  1976. char *v2 = (char*)vp->GetTo_Val();
  1977. for (int i = 0; i < Len; i++)
  1978. if (v1[i] != v2[i])
  1979. return false;
  1980. return true;
  1981. } // end of IsEqual
  1982. /***********************************************************************/
  1983. /* FormatValue: This function set vp (a STRING value) to the string */
  1984. /* constructed from its own value formated using the fmt format. */
  1985. /* This function assumes that the format matches the value type. */
  1986. /***********************************************************************/
  1987. bool BINVAL::FormatValue(PVAL vp, char *fmt)
  1988. {
  1989. char *buf = (char*)vp->GetTo_Val(); // Should be big enough
  1990. int n = sprintf(buf, fmt, Len, Binp);
  1991. return (n > vp->GetValLen());
  1992. } // end of FormatValue
  1993. /***********************************************************************/
  1994. /* BINVAL SetFormat function (used to set SELECT output format). */
  1995. /***********************************************************************/
  1996. bool BINVAL::SetConstFormat(PGLOBAL, FORMAT& fmt)
  1997. {
  1998. fmt.Type[0] = 'B';
  1999. fmt.Length = Clen;
  2000. fmt.Prec = 0;
  2001. return false;
  2002. } // end of SetConstFormat
  2003. /* -------------------------- Class DTVAL ---------------------------- */
  2004. /***********************************************************************/
  2005. /* DTVAL public constructor for new void values. */
  2006. /***********************************************************************/
  2007. DTVAL::DTVAL(PGLOBAL g, int n, int prec, PSZ fmt)
  2008. : TYPVAL<int>((int)0, TYPE_DATE)
  2009. {
  2010. if (!fmt) {
  2011. Pdtp = NULL;
  2012. Sdate = NULL;
  2013. DefYear = 0;
  2014. Len = n;
  2015. } else
  2016. SetFormat(g, fmt, n, prec);
  2017. //Type = TYPE_DATE;
  2018. } // end of DTVAL constructor
  2019. /***********************************************************************/
  2020. /* DTVAL public constructor from int. */
  2021. /***********************************************************************/
  2022. DTVAL::DTVAL(int n) : TYPVAL<int>(n, TYPE_DATE)
  2023. {
  2024. Pdtp = NULL;
  2025. Len = 19;
  2026. //Type = TYPE_DATE;
  2027. Sdate = NULL;
  2028. DefYear = 0;
  2029. } // end of DTVAL constructor
  2030. /***********************************************************************/
  2031. /* Set format so formatted dates can be converted on input/output. */
  2032. /***********************************************************************/
  2033. bool DTVAL::SetFormat(PGLOBAL g, PSZ fmt, int len, int year)
  2034. {
  2035. Pdtp = MakeDateFormat(g, fmt, true, true, (year > 9999) ? 1 : 0);
  2036. Sdate = (char*)PlugSubAlloc(g, NULL, len + 1);
  2037. DefYear = (int)((year > 9999) ? (year - 10000) : year);
  2038. Len = len;
  2039. return false;
  2040. } // end of SetFormat
  2041. /***********************************************************************/
  2042. /* Set format from the format of another date value. */
  2043. /***********************************************************************/
  2044. bool DTVAL::SetFormat(PGLOBAL g, PVAL valp)
  2045. {
  2046. DTVAL *vp;
  2047. if (valp->GetType() != TYPE_DATE) {
  2048. sprintf(g->Message, MSG(NO_FORMAT_TYPE), valp->GetType());
  2049. return true;
  2050. } else
  2051. vp = (DTVAL*)valp;
  2052. Len = vp->Len;
  2053. Pdtp = vp->Pdtp;
  2054. Sdate = (char*)PlugSubAlloc(g, NULL, Len + 1);
  2055. DefYear = vp->DefYear;
  2056. return false;
  2057. } // end of SetFormat
  2058. /***********************************************************************/
  2059. /* We need TimeShift because the mktime C function does a correction */
  2060. /* for local time zone that we want to override for DB operations. */
  2061. /***********************************************************************/
  2062. void DTVAL::SetTimeShift(void)
  2063. {
  2064. struct tm dtm;
  2065. memset(&dtm, 0, sizeof(dtm));
  2066. dtm.tm_mday=2;
  2067. dtm.tm_mon=0;
  2068. dtm.tm_year=70;
  2069. Shift = (int)mktime(&dtm) - 86400;
  2070. if (trace)
  2071. htrc("DTVAL Shift=%d\n", Shift);
  2072. } // end of SetTimeShift
  2073. // Added by Alexander Barkov
  2074. static void TIME_to_localtime(struct tm *tm, const MYSQL_TIME *ltime)
  2075. {
  2076. bzero(tm, sizeof(*tm));
  2077. tm->tm_year= ltime->year - 1900;
  2078. tm->tm_mon= ltime->month - 1;
  2079. tm->tm_mday= ltime->day;
  2080. mktime(tm); // set tm->tm_wday tm->yday fields to get proper day name (OB)
  2081. tm->tm_hour= ltime->hour;
  2082. tm->tm_min= ltime->minute;
  2083. tm->tm_sec= ltime->second;
  2084. } // end of TIME_to_localtime
  2085. // Added by Alexander Barkov
  2086. static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm)
  2087. {
  2088. MYSQL_TIME ltime;
  2089. thd_gmt_sec_to_TIME(current_thd, &ltime, (my_time_t) *timep);
  2090. TIME_to_localtime(tm, &ltime);
  2091. return tm;
  2092. } // end of gmtime_mysql
  2093. /***********************************************************************/
  2094. /* GetGmTime: returns a pointer to a static tm structure obtained */
  2095. /* though the gmtime C function. The purpose of this function is to */
  2096. /* extend the range of valid dates by accepting negative time values. */
  2097. /***********************************************************************/
  2098. struct tm *DTVAL::GetGmTime(struct tm *tm_buffer)
  2099. {
  2100. struct tm *datm;
  2101. time_t t = (time_t)Tval;
  2102. if (Tval < 0) {
  2103. int n;
  2104. for (n = 0; t < 0; n += 4)
  2105. t += FOURYEARS;
  2106. datm = gmtime_mysql(&t, tm_buffer);
  2107. if (datm)
  2108. datm->tm_year -= n;
  2109. } else
  2110. datm = gmtime_mysql(&t, tm_buffer);
  2111. return datm;
  2112. } // end of GetGmTime
  2113. // Added by Alexander Barkov
  2114. static time_t mktime_mysql(struct tm *ptm)
  2115. {
  2116. MYSQL_TIME ltime;
  2117. localtime_to_TIME(&ltime, ptm);
  2118. ltime.time_type= MYSQL_TIMESTAMP_DATETIME;
  2119. uint error_code;
  2120. time_t t= TIME_to_timestamp(current_thd, &ltime, &error_code);
  2121. return error_code ? (time_t) -1 : t;
  2122. }
  2123. /***********************************************************************/
  2124. /* MakeTime: calculates a date value from a tm structures using the */
  2125. /* mktime C function. The purpose of this function is to extend the */
  2126. /* range of valid dates by accepting to set negative time values. */
  2127. /***********************************************************************/
  2128. bool DTVAL::MakeTime(struct tm *ptm)
  2129. {
  2130. int n, y = ptm->tm_year;
  2131. time_t t = mktime_mysql(ptm);
  2132. if (trace > 1)
  2133. htrc("MakeTime from (%d,%d,%d,%d,%d,%d)\n",
  2134. ptm->tm_year, ptm->tm_mon, ptm->tm_mday,
  2135. ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
  2136. if (t == -1) {
  2137. if (y < 1 || y > 71)
  2138. return true;
  2139. for (n = 0; t == -1 && n < 20; n++) {
  2140. ptm->tm_year += 4;
  2141. t = mktime_mysql(ptm);
  2142. } // endfor t
  2143. if (t == -1)
  2144. return true;
  2145. if ((t -= (n * FOURYEARS)) > 2000000000)
  2146. return true;
  2147. }
  2148. Tval= (int) t;
  2149. if (trace > 1)
  2150. htrc("MakeTime Ival=%d\n", Tval);
  2151. return false;
  2152. } // end of MakeTime
  2153. /***********************************************************************/
  2154. /* Make a time_t datetime from its components (YY, MM, DD, hh, mm, ss) */
  2155. /***********************************************************************/
  2156. bool DTVAL::MakeDate(PGLOBAL g, int *val, int nval)
  2157. {
  2158. int i, m;
  2159. int n;
  2160. bool rc = false;
  2161. struct tm datm;
  2162. bzero(&datm, sizeof(datm));
  2163. datm.tm_mday=1;
  2164. datm.tm_mon=0;
  2165. datm.tm_year=70;
  2166. if (trace > 1)
  2167. htrc("MakeDate from(%d,%d,%d,%d,%d,%d) nval=%d\n",
  2168. val[0], val[1], val[2], val[3], val[4], val[5], nval);
  2169. for (i = 0; i < nval; i++) {
  2170. n = val[i];
  2171. // if (trace > 1)
  2172. // htrc("i=%d n=%d\n", i, n);
  2173. switch (i) {
  2174. case 0:
  2175. if (n >= 1900)
  2176. n -= 1900;
  2177. datm.tm_year = n;
  2178. // if (trace > 1)
  2179. // htrc("n=%d tm_year=%d\n", n, datm.tm_year);
  2180. break;
  2181. case 1:
  2182. // If mktime handles apparently correctly large or negative
  2183. // day values, it is not the same for months. Therefore we
  2184. // do the ajustment here, thus mktime has not to do it.
  2185. if (n > 0) {
  2186. m = (n - 1) % 12;
  2187. n = (n - 1) / 12;
  2188. } else {
  2189. m = 11 + n % 12;
  2190. n = n / 12 - 1;
  2191. } // endfi n
  2192. datm.tm_mon = m;
  2193. datm.tm_year += n;
  2194. // if (trace > 1)
  2195. // htrc("n=%d m=%d tm_year=%d tm_mon=%d\n", n, m, datm.tm_year, datm.tm_mon);
  2196. break;
  2197. case 2:
  2198. // For days, big or negative values may also cause problems
  2199. m = n % 1461;
  2200. n = 4 * (n / 1461);
  2201. if (m < 0) {
  2202. m += 1461;
  2203. n -= 4;
  2204. } // endif m
  2205. datm.tm_mday = m;
  2206. datm.tm_year += n;
  2207. // if (trace > 1)
  2208. // htrc("n=%d m=%d tm_year=%d tm_mon=%d\n", n, m, datm.tm_year, datm.tm_mon);
  2209. break;
  2210. case 3: datm.tm_hour = n; break;
  2211. case 4: datm.tm_min = n; break;
  2212. case 5: datm.tm_sec = n; break;
  2213. } // endswitch i
  2214. } // endfor i
  2215. if (trace > 1)
  2216. htrc("MakeDate datm=(%d,%d,%d,%d,%d,%d)\n",
  2217. datm.tm_year, datm.tm_mon, datm.tm_mday,
  2218. datm.tm_hour, datm.tm_min, datm.tm_sec);
  2219. // Pass g to have an error return or NULL to set invalid dates to 0
  2220. if (MakeTime(&datm))
  2221. if (g) {
  2222. strcpy(g->Message, MSG(BAD_DATETIME));
  2223. rc = true;
  2224. } else
  2225. Tval = 0;
  2226. return rc;
  2227. } // end of MakeDate
  2228. /***********************************************************************/
  2229. /* DTVAL SetValue: copy the value of another Value object. */
  2230. /* This function allows conversion if chktype is false. */
  2231. /***********************************************************************/
  2232. bool DTVAL::SetValue_pval(PVAL valp, bool chktype)
  2233. {
  2234. if (valp != this) {
  2235. if (chktype && Type != valp->GetType())
  2236. return true;
  2237. if (!(Null = valp->IsNull() && Nullable)) {
  2238. if (Pdtp && !valp->IsTypeNum()) {
  2239. int ndv;
  2240. int dval[6];
  2241. ndv = ExtractDate(valp->GetCharValue(), Pdtp, DefYear, dval);
  2242. MakeDate(NULL, dval, ndv);
  2243. } else
  2244. Tval = valp->GetIntValue();
  2245. } else
  2246. Reset();
  2247. } // endif valp
  2248. return false;
  2249. } // end of SetValue
  2250. /***********************************************************************/
  2251. /* SetValue: convert chars extracted from a line to date value. */
  2252. /***********************************************************************/
  2253. bool DTVAL::SetValue_char(char *p, int n)
  2254. {
  2255. bool rc= 0;
  2256. if (Pdtp) {
  2257. char *p2;
  2258. int ndv;
  2259. int dval[6];
  2260. if (n > 0) {
  2261. // Trim trailing blanks
  2262. for (p2 = p + n -1; p < p2 && *p2 == ' '; p2--);
  2263. if ((rc = (n = p2 - p + 1) > Len))
  2264. n = Len;
  2265. memcpy(Sdate, p, n);
  2266. } // endif n
  2267. Sdate[n] = '\0';
  2268. ndv = ExtractDate(Sdate, Pdtp, DefYear, dval);
  2269. MakeDate(NULL, dval, ndv);
  2270. if (trace > 1)
  2271. htrc(" setting date: '%s' -> %d\n", Sdate, Tval);
  2272. Null = (Nullable && ndv == 0);
  2273. } else {
  2274. rc = TYPVAL<int>::SetValue_char(p, n);
  2275. Null = (Nullable && Tval == 0);
  2276. } // endif Pdtp
  2277. return rc;
  2278. } // end of SetValue
  2279. /***********************************************************************/
  2280. /* SetValue: convert a char string to date value. */
  2281. /***********************************************************************/
  2282. void DTVAL::SetValue_psz(PSZ p)
  2283. {
  2284. if (Pdtp) {
  2285. int ndv;
  2286. int dval[6];
  2287. strncpy(Sdate, p, Len);
  2288. Sdate[Len] = '\0';
  2289. ndv = ExtractDate(Sdate, Pdtp, DefYear, dval);
  2290. MakeDate(NULL, dval, ndv);
  2291. if (trace > 1)
  2292. htrc(" setting date: '%s' -> %d\n", Sdate, Tval);
  2293. Null = (Nullable && ndv == 0);
  2294. } else {
  2295. TYPVAL<int>::SetValue_psz(p);
  2296. Null = (Nullable && Tval == 0);
  2297. } // endif Pdtp
  2298. } // end of SetValue
  2299. /***********************************************************************/
  2300. /* DTVAL SetValue: set value with a value extracted from a block. */
  2301. /***********************************************************************/
  2302. void DTVAL::SetValue_pvblk(PVBLK blk, int n)
  2303. {
  2304. if (Pdtp && !::IsTypeNum(blk->GetType())) {
  2305. int ndv;
  2306. int dval[6];
  2307. ndv = ExtractDate(blk->GetCharValue(n), Pdtp, DefYear, dval);
  2308. MakeDate(NULL, dval, ndv);
  2309. } else
  2310. Tval = blk->GetIntValue(n);
  2311. } // end of SetValue
  2312. /***********************************************************************/
  2313. /* DTVAL GetCharString: get string representation of a date value. */
  2314. /***********************************************************************/
  2315. char *DTVAL::GetCharString(char *p)
  2316. {
  2317. if (Pdtp) {
  2318. size_t n = 0;
  2319. struct tm tm, *ptm= GetGmTime(&tm);
  2320. if (ptm)
  2321. n = strftime(Sdate, Len + 1, Pdtp->OutFmt, ptm);
  2322. if (!n) {
  2323. *Sdate = '\0';
  2324. strncat(Sdate, "Error", Len + 1);
  2325. } // endif n
  2326. return Sdate;
  2327. } else
  2328. sprintf(p, "%d", Tval);
  2329. //Null = false; ??????????????
  2330. return p;
  2331. } // end of GetCharString
  2332. /***********************************************************************/
  2333. /* DTVAL ShowValue: get string representation of a date value. */
  2334. /***********************************************************************/
  2335. char *DTVAL::ShowValue(char *buf, int len)
  2336. {
  2337. if (Pdtp) {
  2338. char *p;
  2339. if (!Null) {
  2340. size_t m, n = 0;
  2341. struct tm tm, *ptm = GetGmTime(&tm);
  2342. if (Len < len) {
  2343. p = buf;
  2344. m = len;
  2345. } else {
  2346. p = Sdate;
  2347. m = Len + 1;
  2348. } // endif Len
  2349. if (ptm)
  2350. n = strftime(p, m, Pdtp->OutFmt, ptm);
  2351. if (!n) {
  2352. *p = '\0';
  2353. strncat(p, "Error", m);
  2354. } // endif n
  2355. } else
  2356. p = ""; // DEFAULT VALUE ???
  2357. return p;
  2358. } else
  2359. return TYPVAL<int>::ShowValue(buf, len);
  2360. } // end of ShowValue
  2361. #if 0 // Not used by CONNECT
  2362. /***********************************************************************/
  2363. /* Returns a member of the struct tm representation of the date. */
  2364. /***********************************************************************/
  2365. bool DTVAL::GetTmMember(OPVAL op, int& mval)
  2366. {
  2367. bool rc = false;
  2368. struct tm tm, *ptm = GetGmTime(&tm);
  2369. switch (op) {
  2370. case OP_MDAY: mval = ptm->tm_mday; break;
  2371. case OP_MONTH: mval = ptm->tm_mon + 1; break;
  2372. case OP_YEAR: mval = ptm->tm_year + 1900; break;
  2373. case OP_WDAY: mval = ptm->tm_wday + 1; break;
  2374. case OP_YDAY: mval = ptm->tm_yday + 1; break;
  2375. case OP_QUART: mval = ptm->tm_mon / 3 + 1; break;
  2376. default:
  2377. rc = true;
  2378. } // endswitch op
  2379. return rc;
  2380. } // end of GetTmMember
  2381. /***********************************************************************/
  2382. /* Calculates the week number of the year for the internal date value.*/
  2383. /* The International Standard ISO 8601 has decreed that Monday shall */
  2384. /* be the first day of the week. A week that lies partly in one year */
  2385. /* and partly in another is assigned a number in the year in which */
  2386. /* most of its days lie. That means that week number 1 of any year is */
  2387. /* the week that contains the January 4th. */
  2388. /***********************************************************************/
  2389. bool DTVAL::WeekNum(PGLOBAL g, int& nval)
  2390. {
  2391. // w is the start of the week SUN=0, MON=1, etc.
  2392. int m, n, w = nval % 7;
  2393. struct tm tm, *ptm = GetGmTime(&tm);
  2394. // Which day is January 4th of this year?
  2395. m = (367 + ptm->tm_wday - ptm->tm_yday) % 7;
  2396. // When does the first week begins?
  2397. n = 3 - (7 + m - w) % 7;
  2398. // Now calculate the week number
  2399. if (!(nval = (7 + ptm->tm_yday - n) / 7))
  2400. nval = 52;
  2401. // Everything should be Ok
  2402. return false;
  2403. } // end of WeekNum
  2404. #endif // 0
  2405. /***********************************************************************/
  2406. /* FormatValue: This function set vp (a STRING value) to the string */
  2407. /* constructed from its own value formated using the fmt format. */
  2408. /* This function assumes that the format matches the value type. */
  2409. /***********************************************************************/
  2410. bool DTVAL::FormatValue(PVAL vp, char *fmt)
  2411. {
  2412. char *buf = (char*)vp->GetTo_Val(); // Should be big enough
  2413. struct tm tm, *ptm = GetGmTime(&tm);
  2414. if (trace > 1)
  2415. htrc("FormatValue: ptm=%p len=%d\n", ptm, vp->GetValLen());
  2416. if (ptm) {
  2417. size_t n = strftime(buf, vp->GetValLen(), fmt, ptm);
  2418. if (trace > 1)
  2419. htrc("strftime: n=%d buf=%s\n", n, (n) ? buf : "???");
  2420. return (n == 0);
  2421. } else
  2422. return true;
  2423. } // end of FormatValue
  2424. /* -------------------------- End of Value --------------------------- */