Posts

Showing posts with the label Parameters

C# Parameterized Query MySQL With `in` Clause

Answer : This is not possible in MySQL. You can create a required number of parameters and do UPDATE ... IN (?,?,?,?). This prevents injection attacks (but still requires you to rebuild the query for each parameter count). Other way is to pass a comma-separated string and parse it. You could build up the parametrised query "on the fly" based on the (presumably) variable number of parameters, and iterate over that to pass them in. So, something like: List foo; // assuming you have a List of items, in reality, it may be a List<int> or a List<myObject> with an id property, etc. StringBuilder query = new StringBuilder( "UPDATE TABLE_1 SET STATUS = ? WHERE ID IN ( ?") for( int i = 1; i++; i < foo.Count ) { // Bit naive query.Append( ", ?" ); } query.Append( " );" ); MySqlCommand m = new MySqlCommand(query.ToString()); for( int i = 1; i++; i < foo.Count ) { m.Parameters.Add(new MySqlParameter(...)); } You cann...

CakePHP TypeConverterTrait (trait)

Type converter trait Namespace: Cake\Database Method Summary cast() public Converts a give value to a suitable database value based on type and return relevant internal statement type matchTypes() public Matches columns to corresponding types Method Detail cast() public cast ( mixed $value , mixed $type ) Converts a give value to a suitable database value based on type and return relevant internal statement type Parameters mixed $value The value to cast \Cake\Database\TypeInterface|string|int $type optional The type name or type instance to use. Returns array list containing converted value and internal type matchTypes() public matchTypes ( array $columns , array $types ) Matches columns to corresponding types Both c o l u m n s a n d columns and co l u mn s an d types should either be numeric based or string key based at the same time. Parameters array $columns list or associative array of columns and...

Can I Create View With Parameter In MySQL?

Answer : Actually if you create func: create function p1() returns INTEGER DETERMINISTIC NO SQL return @p1; and view: create view h_parm as select * from sw_hardware_big where unit_id = p1() ; Then you can call a view with a parameter: select s.* from (select @p1:=12 p) parm , h_parm s; I hope it helps. CREATE VIEW MyView AS SELECT Column, Value FROM Table; SELECT Column FROM MyView WHERE Value = 1; Is the proper solution in MySQL, some other SQLs let you define Views more exactly. Note: Unless the View is very complicated, MySQL will optimize this just fine.