A
A
Andrello2014-05-25 21:57:21
MySQL
Andrello, 2014-05-25 21:57:21

Trimming zeros on insert query

Trim zeros on insert query
"INSERT INTO `plug_cat_vals` (`write_id`, `code`, `attr`, `value`) VALUES (%s, '00000000771' %s, '')"
00000000771 -> 771
varchar fields remain 24
must be left with zeros

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
cmx, 2014-05-26
@cmx

Perhaps it makes sense to convert the column to int with the ZEROFILL parameter to automatically fill with zeros.
If it is important with varchar and you really have varchar and you are passing a string, then it is highly likely that conversion to int takes place, and most likely somewhere in the model layer.

S
Stepan, 2014-05-25
@L3n1n

1. The request in the example is not working at all.
2. Are there no zeros when selecting in scripts, or does it cut right when pasting?

A
Andrello, 2014-05-25
@Andrello

when inserting, here is the complete one:
$this->db->Run("INSERT INTO `plug_cat_vals` (`write_id`, `code`, `attr`, `value`) VALUES (%s, '".(string)$ itemCode."' %s, '')", array( $item['id'], 17) );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question