Announcement

Collapse
No announcement yet.

Created SQL string issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Created SQL string issue

    Hello,

    I have an issue with the SQL string that is being crearted in Mirth Connect.

    The code below gives issues in SQL.

    var studyDate = channelMap.get('studyDate')
    var sqlQuery = "INSERT IGNORE INTO sr_entries_1 (StudyDate) VALUES ('" + studyDate + "')";
    var result = dbConn.executeUpdate(sqlQuery);

    It returns the error:

    Msg 8152, Level 16, State 14, Line 1
    String or binary data would be truncated.
    The statement has been terminated.

    In the SQL profiler I see that the sql string look like below (with an "enter" before the last ':

    INSERT IGNORE INTO sr_entries_1(StudyDate) VALUES ('20180710
    ')

    If I change this string manually like below than I don't get this error message.

    INSERT IGNORE INTO sr_entries_1(StudyDate) VALUES ('20180710')

    How can I prevent this from happening, so the sql string must not have a "enter" before the last ' ?

  • #2
    Issue has been solved. I looked at the file (using notepad++) that I reading with a file reader to populate my variables. Each line has a CR and LF so that was the issue.

    Using a string replace I "removed" the CR and LF

    string.replace(/[\r\n]/g, '');

    Comment

    Working...
    X