iregex doesn't work properly

36 views
Skip to first unread message

Denis Yu

unread,
Aug 27, 2016, 9:06:50 AM8/27/16
to Django users
Hi,

Someone please, help to resolve my problem with iregex !

using Django 1.9
mysql Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
python 2.7

I got the record in mysql in table Order_process:

+-----+------+---------------------------+---------------------+----------+------------+
| id  | step | step_description          | date_step           | order_id | manager_id |
+-----+------+---------------------------+---------------------+----------+------------+
| 241 |    1 | заказ роутера             | 2016-08-21 11:03:16 |      170 |          1 |
+-----+------+---------------------------+---------------------+----------+------------+
 
next, I'd like to get thi record by queryset:
    str_iregex = '^заказ роутер.$'
    orders = Order_process.objects.filter(step_description__iregex = str_iregex , step = 1).order_by('-id')

But the got no result.
pls help








Sergiy Khohlov

unread,
Aug 27, 2016, 9:28:18 AM8/27/16
to django-users

Try to check this via mysql shell. It will be nice to know codepage at system, database and django project. Have you checked this with Latin charset already ?


27 серп. 2016 16:06 "Denis Yu" <denis...@gmail.com> пише:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8da615e3-c990-4359-9851-32d12b5d9fb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Denis Yu

unread,
Aug 27, 2016, 1:13:42 PM8/27/16
to Django users
Sergiy,

Thank you for reply

I checked following parameters:

mysql> show create table clients_order_process; (clients_order_process - it's my table)

| clients_order_process | CREATE TABLE `clients_order_process` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `step` int(11) NOT NULL,
  `step_description` longtext NOT NULL,
  `date_step` datetime NOT NULL,
  `order_id` int(11) NOT NULL,
  `manager_id` int(11),
  PRIMARY KEY (`id`),
  KEY `clients_order_proces_order_id_1eb697bf_fk_clients_order_id` (`order_id`),
  KEY `clients_order_process_8784215c` (`manager_id`),
  CONSTRAINT `clients_order_proces_order_id_1eb697bf_fk_clients_order_id` FOREIGN KEY (`order_id`) REFERENCES `clients_order` (`id`),
  CONSTRAINT `clients_order_process_manager_id_f3e3fa60_fk_auth_user_id` FOREIGN KEY (`manager_id`) REFERENCES `auth_user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=249 DEFAULT CHARSET=utf8 |


mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0,01 sec)


so, I found  | character_set_server     | latin1 
is this the problem?





суббота, 27 августа 2016 г., 19:28:18 UTC+6 пользователь Sergiy Khohlov написал:

Try to check this via mysql shell. It will be nice to know codepage at system, database and django project. Have you checked this with Latin charset already ?

27 серп. 2016 16:06 "Denis Yu" <denis...@gmail.com> пише:
Hi,

Someone please, help to resolve my problem with iregex !

using Django 1.9
mysql Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
python 2.7

I got the record in mysql in table Order_process:

+-----+------+---------------------------+---------------------+----------+------------+
| id  | step | step_description          | date_step           | order_id | manager_id |
+-----+------+---------------------------+---------------------+----------+------------+
| 241 |    1 | заказ роутера             | 2016-08-21 11:03:16 |      170 |          1 |
+-----+------+---------------------------+---------------------+----------+------------+
 
next, I'd like to get thi record by queryset:
    str_iregex = '^заказ роутер.$'
    orders = Order_process.objects.filter(step_description__iregex = str_iregex , step = 1).order_by('-id')

But the got no result.
pls help








--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Sergiy Khohlov

unread,
Aug 27, 2016, 2:58:24 PM8/27/16
to django-users
Not sure that problem is related to character_set_server due to highest priority of create table option.  I'm using postgres as default.  I'm proposing to check latin chars and turn on mysql debugging  in case of your permission. 
  localization coding  of MySql is  here http://dev.mysql.com/doc/refman/5.7/en/charset-syntax.html


 At this moment I propose do next : 
1)  check log for sql request from django to Mysql 
2) execute next sql from mysql :    SELECT id from Order_process WHERE step_description REGEXP BINARY '^заказ роутера%';


 Why are you not using raw string in your regex ?


Many thanks,

Serge


+380 636150445
skype: skhohlov

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Denis Yu

unread,
Aug 28, 2016, 7:18:25 AM8/28/16
to Django users
  1. Here is the result in logging table:

mysql> select * from mysql.general_log;
....
| 2016-08-28 14:14:17.188990 | crm[crm] @ localhost [] |       934 |         0 | Query        | SELECT COUNT(*) AS `__count` FROM `clients_order_process` WHERE (`clients_order_process`.`step` = 1 AND `clients_order_process`.`step_description` REGEXP '^заказ роутер.$')
....




the record exists in table:
mysql> select id, step, step_description from clients_order_process where id =241;
+-----+------+---------------------------+
| id  | step | step_description          |
+-----+------+---------------------------+
| 241 |    1 | заказ роутера             |
+-----+------+---------------------------+
1 row in set (0,00 sec)



  1. the result of query  SELECT id from Order_process WHERE step_description REGEXP BINARY '^заказ роутера%'; :

mysql>  SELECT id from clients_order_process WHERE step_description REGEXP BINARY '^заказ роутера%';
Empty set (0,00 sec)



mysql> select * from mysql.general_log;
+----------------------------+-------------------------+-----------+-----------+--------------+---------------------------------------------------------------------------------------------------------+
| event_time                 | user_host               | thread_id | server_id | command_type | argument                                                                                                |
+----------------------------+-------------------------+-----------+-----------+--------------+---------------------------------------------------------------------------------------------------------+
| 2016-08-28 14:18:20.921420 | crm[crm] @ localhost [] |       857 |         0 | Query        | SELECT id from clients_order_process WHERE step_description REGEXP BINARY '^заказ роутера%'   


Pls, explain, what way do you recommend using raw string?


thanks




воскресенье, 28 августа 2016 г., 0:58:24 UTC+6 пользователь Sergiy Khohlov написал:

Sergiy Khohlov

unread,
Aug 28, 2016, 11:11:56 AM8/28/16
to django-users
I've made mistake : "$" should be in request not "%"

 this request "SELECT COUNT(*) AS `__count` FROM `clients_order_process` WHERE (`clients_order_process`.`step` = 1 AND `clients_order_process`.`step_description` REGEXP '^заказ роутер.$')"  informs that django sends data correctly.

Many thanks,

Serge


+380 636150445
skype: skhohlov

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Denis Yu

unread,
Aug 30, 2016, 3:51:34 AM8/30/16
to Django users
Yes, i've seen.

could you pls say one more ideas to check?




воскресенье, 28 августа 2016 г., 21:11:56 UTC+6 пользователь Sergiy Khohlov написал:

Sergiy Khohlov

unread,
Aug 30, 2016, 4:37:24 AM8/30/16
to django-users
You are making me confused. 
1) Django  send data to db and SQL is correct
2) MySQL returns correct result
3) Django shows right data

 Which one step has issue ? 

Many thanks,

Serge


+380 636150445
skype: skhohlov

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Denis Yu

unread,
Aug 30, 2016, 4:58:45 AM8/30/16
to Django users

sorry, may be I explained the result of testing incorrectly(
pls let me make another try):

here is the record in log table:
| 2016-08-28 14:14:17.188990 | crm[crm] @ localhost [] |       934 |         0 | Query        | SELECT COUNT(*) AS `__count` FROM `clients_order_process` WHERE (`clients_order_process`.`step` = 1 AND `clients_order_process`.`step_description` REGEXP '^заказ роутер.$')


Django doesn't return any data. But I'm checking the record in table and it exists:

mysql> select id, step, step_description from clients_order_process where id =241;
+-----+------+---------------------------+
| id  | step | step_description          |
+-----+------+---------------------------+
| 241 |    1 | заказ роутера             |
+-----+------+---------------------------+
1 row in set (0,00 sec)








вторник, 30 августа 2016 г., 14:37:24 UTC+6 пользователь Sergiy Khohlov написал:

Sergiy Khohlov

unread,
Aug 30, 2016, 5:31:51 AM8/30/16
to django-users
try to execute from console : 
 SELECT id FROM `clients_order_process` WHERE  `clients_order_process`.`step_description` REGEXP '^заказ роутер.$'

Many thanks,

Serge


+380 636150445
skype: skhohlov

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Denis Yu

unread,
Aug 30, 2016, 6:00:59 AM8/30/16
to Django users
Here is the results:
mysql> SELECT id FROM `clients_order_process` WHERE  `clients_order_process`.`step_description` REGEXP '^заказ роутер.$';
Empty set (0,00 sec)


while:
mysql> SELECT id FROM `clients_order_process` WHERE  `clients_order_process`.`step_description` REGEXP '^заказ роутера$';
+-----+
| id  |
+-----+
| 241 |
+-----+

1 row in set (0,00 sec)


вторник, 30 августа 2016 г., 15:31:51 UTC+6 пользователь Sergiy Khohlov написал:

Sergiy Khohlov

unread,
Aug 30, 2016, 6:15:52 AM8/30/16
to django-users
 this one problem is not related  to the django. It is Mysql special configuration.   Dot  is not working in your system as expected : 

 Looks like your localization is broking regular expression in MySQL. 
In this case please ask this question in  MySQL topic not django.  

Many thanks,

Serge


+380 636150445
skype: skhohlov

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages