void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length) { byte[] array = null; try { array = ((MySqlGeometry)val)._valBinary; } catch { array = (val as byte[]); } if (array == null) { MySqlGeometry mySqlGeometry = new MySqlGeometry(0.0, 0.0); MySqlGeometry.TryParse(val.ToString(), out mySqlGeometry); array = mySqlGeometry._valBinary; } byte[] array2 = new byte[25]; for (int i = 0; i < array.Length; i++) { if (array.Length < 25) { array2[i + 4] = array[i]; } else { array2[i] = array[i]; } } packet.WriteStringNoNull("_binary "); packet.WriteByte(39); MySqlGeometry.EscapeByteArray(array2, 25, packet); packet.WriteByte(39); }
public static MySqlGeometry Parse(string value) { if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException("value"); } if (!value.Contains("SRID") && !value.Contains("POINT(") && !value.Contains("POINT (")) { throw new FormatException("String does not contain a valid geometry value"); } MySqlGeometry result = new MySqlGeometry(0.0, 0.0); MySqlGeometry.TryParse(value, out result); return(result); }
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length) { byte[] buffToWrite = null; try { buffToWrite = ((MySqlGeometry)val)._valBinary; } catch { buffToWrite = val as Byte[]; } if (buffToWrite == null) { MySqlGeometry v = new MySqlGeometry(0, 0); MySqlGeometry.TryParse(val.ToString(), out v); buffToWrite = v._valBinary; } byte[] result = new byte[GEOMETRY_LENGTH]; for (int i = 0; i < buffToWrite.Length; i++) { if (buffToWrite.Length < GEOMETRY_LENGTH) { result[i + 4] = buffToWrite[i]; } else { result[i] = buffToWrite[i]; } } packet.WriteStringNoNull("_binary "); packet.WriteByte((byte)'\''); EscapeByteArray(result, GEOMETRY_LENGTH, packet); packet.WriteByte((byte)'\''); }