c# - Accurately Set the MySqlCommand Parameter Size -


how can accurately pass in proper data size following line:

objcmd.parameters.add(_pns[i], _dts[i]).value = _pvs[i];

it passed array of parameternames, mysqldbtypes, however, able pass in data size well... according mysqldbtype passed in.

i know text, varchar, etc... lengths vary, else?

p.s. c# using latest version of mysql, , latest version of mysql .net connector

here's have far, not seem accurate assume should be.

objcmd.parameters.add(_pns[i], _dts[i], _estimatedsize(_pvs[i])).value = _pvs[i];

// method pretty dumb want fast. internal int _estimatedsize(object _val) {     if (_val == null || _val == dbnull.value)         return 4; // size of null     if (_val byte[])         return (_val byte[]).length;     if (_val string)         return (_val string).length * 4; // account utf-8     if (_val decimal || _val float)         return 64;     if (_val bool)         return 1;     return 32; } 

create 2 array sqldtype , sqlsize

sqldbtype[] sqldtype = new sqldbtype[] {sqldbtype.int, sqldbtype.float, sqldbtype.smallint, sqldbtype.tinyint}; int[] sqlsize = new int[] { 4, 8, 2, 1 }; sqldbtype type = sqldbtype.float; int iindex = array.indexof(sqldtype, type); int isize = -1; if (iindex > -1)     isize = sqlsize[iindex]; 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -