<p>Hello Daniel<br>
Think i found way how to properly escape blob strings.<br>
need to execute <code>SET bytea_output=escape;</code> command when connection created<br>
This maybe done in function <a href="https://github.com/kamailio/kamailio/blob/master/src/modules/db_postgres/km_pg_con.c#L48-L152"><code>db_postgres_new_connection</code></a>.</p>
<p>By default psql output BLOBs in hex format. After <code>SET bytea_output=escape;</code> this behaviour is changed to expected by Kamailio.</p>
<pre><code>pg1b:~$ psql kamailio
psql (9.6.3)
Type "help" for help.

kamailio=# CREATE TABLE blob_table (blob bytea);
CREATE TABLE
kamailio=# INSERT INTO blob_table VALUES ('Kamailio');
INSERT 0 1
kamailio=# SELECT * FROM blob_table;
        blob        
--------------------
 \x4b616d61696c696f
(1 row)

kamailio=# SET bytea_output=escape;
SET
kamailio=# SELECT * FROM blob_table;
   blob   
----------
 Kamailio
(1 row)

kamailio=# 
</code></pre>
<p>Could you suggest patch and then i will test on my servers.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1255#issuecomment-427683551">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZSheczoYnh0f6g6cYL9rvL1EA6YEks5uimFtgaJpZM4PoBLO">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZdjhwlR-LSJp55fmBsJ-LbsTaTxiks5uimFtgaJpZM4PoBLO.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@sergey-safarov in #1255: Hello Daniel\r\nThink i found way how to properly escape blob strings.\r\nneed to execute `SET bytea_output=escape;` command when connection created\r\nThis maybe done in function [`db_postgres_new_connection`](https://github.com/kamailio/kamailio/blob/master/src/modules/db_postgres/km_pg_con.c#L48-L152).\r\n\r\nBy default psql output BLOBs in hex format. After `SET bytea_output=escape;` this behaviour is changed to expected by Kamailio.\r\n```\r\npg1b:~$ psql kamailio\r\npsql (9.6.3)\r\nType \"help\" for help.\r\n\r\nkamailio=# CREATE TABLE blob_table (blob bytea);\r\nCREATE TABLE\r\nkamailio=# INSERT INTO blob_table VALUES ('Kamailio');\r\nINSERT 0 1\r\nkamailio=# SELECT * FROM blob_table;\r\n        blob        \r\n--------------------\r\n \\x4b616d61696c696f\r\n(1 row)\r\n\r\nkamailio=# SET bytea_output=escape;\r\nSET\r\nkamailio=# SELECT * FROM blob_table;\r\n   blob   \r\n----------\r\n Kamailio\r\n(1 row)\r\n\r\nkamailio=# \r\n```\r\nCould you suggest patch and then i will test on my servers."}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1255#issuecomment-427683551"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1255#issuecomment-427683551",
"url": "https://github.com/kamailio/kamailio/issues/1255#issuecomment-427683551",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [kamailio/kamailio] DB Postgres BLOB conversion for presence (#1255)",
"sections": [
{
"text": "",
"activityTitle": "**sergey-safarov**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@sergey-safarov",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1255,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1255#issuecomment-427683551"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 262148814\n}"
}
],
"themeColor": "26292E"
}
]</script>