1 module hunt.database.driver.mysql.impl.codec.MySQLParamDesc; 2 3 import hunt.database.driver.mysql.impl.codec.ColumnDefinition; 4 import hunt.database.driver.mysql.impl.codec.DataFormat; 5 import hunt.database.driver.mysql.impl.codec.DataTypeDesc; 6 7 import hunt.database.base.impl.ParamDesc; 8 import hunt.database.base.Util; 9 10 import hunt.collection.List; 11 import hunt.logging; 12 import hunt.Exceptions; 13 14 import std.conv; 15 import std.variant; 16 import std.algorithm.iteration; 17 18 /** 19 * 20 */ 21 class MySQLParamDesc : ParamDesc { 22 private ColumnDefinition[] _paramDefinitions; 23 24 this(ColumnDefinition[] paramDefinitions) { 25 this._paramDefinitions = paramDefinitions; 26 } 27 28 ColumnDefinition[] paramDefinitions() { 29 return _paramDefinitions; 30 } 31 32 override 33 string prepare(List!(Variant) values) { 34 // warning("values.size: ", values.size()); 35 // warning(toString()); 36 if (values.size() != _paramDefinitions.length) { 37 return buildReport(values); 38 } 39 // for (int i = 0;i < paramDefinitions.length;i++) { 40 // DataType paramDataType = paramDefinitions[i].type(); 41 // Object value = values.get(i); 42 // Object val = DataTypeCodec.prepare(paramDataType, value); 43 // if (val != value) { 44 // if (val == DataTypeCodec.REFUSED_SENTINEL) { 45 // return buildReport(values); 46 // } else { 47 // values.set(i, val); 48 // } 49 // } 50 // } 51 // TODO we can't really achieve type check for params because MySQL prepare response does not provide any useful information for param definitions 52 return null; 53 } 54 55 // reuse from pg 56 private string buildReport(List!(Variant) values) { 57 string[] types; 58 _paramDefinitions.each!((ColumnDefinition column) { 59 DataTypeDesc desc = DataTypes.valueOf(cast(int)column.type); 60 types = types ~ desc.binaryType; 61 }); 62 63 return Util.buildInvalidArgsError(values.toArray(), types); 64 } 65 66 override string toString() { 67 return "MySQLParamDesc{paramDataTypes=" ~ _paramDefinitions.to!string() ~ "}"; 68 } 69 }