Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default final blank space

    Im working in an automatic language translator. In brief, the application uses
    the Replace function to replace certain words in portuguese to their equal in
    spanish. Those words are obtained from a table, wich fields are as shown:
    portuguese (varchar 50) , spanish (varchar 50).

    The application works perfect, but the problem is that some words must only be
    replaced if they are found with a blank endspace. Eg. the chain " ? " must be
    replaced with " a " . Watch carefully .... the chain is not "?" , but " ? ".
    I can save the word " ?" in the database, but I could not find a way to store "
    ? ".

    ?Is there a way to do that?

    Thanks in advance, Im certain that CF will be the future's language, because
    of the great support that we receive.

    Feudalism Guest

  2. Similar Questions and Discussions

    1. about:blank - flash popup is blank
      When going to yahoo maps (the new version that runs on flash9), when clicking on "printable version" I get a blank page that pops up with...
    2. #39485 [NEW]: mkdir() fails when pathname have space(s) on the final
      From: v1d4l0k4 at gmail dot com Operating system: Windows XP (Win32 only) PHP version: 5.2.0 PHP Bug Type: ...
    3. Large Blank Space on the Screen
      I really hope someone can explain this behavior. I have spend quite a bit of time and tried a bunch of things, so far nothing has worked. I have...
    4. PG8 final when
      Dear Developers, when do you plan to announce the final version of 8.0.0? As far as I can remember it was promised by 15. dec. No hurrying, just...
    5. Water in space!The final frontier!
      I have some questions for you as a beginner. Can you import from studio max water made with reactor in director, how.I tried but when i entered in...
  3. #2

    Default Re: final blank space

    I'm not sure what the issue is. The code below adds the string "abcd " (space
    at the end) to the database, then successfully reads it back. What am I
    missing?

    <CFSET chain = "abcd ">

    <CFQUERY NAME="test" DATASOURCE="cflogs">
    INSERT INTO test (logDate) VALUES('#chain#')
    </CFQUERY>

    <!--- this select statement returns one record, the one that was just inserted
    --->
    <CFQUERY NAME="test" DATASOURCE="cflogs">
    SELECT * FROM test WHERE logDate = 'abcd '
    </CFQUERY>

    jdeline Guest

  4. #3

    Default Re: final blank space

    Ok, that works perfect to select the records that end with a blankspace, like
    " abcd " or " myself ". The fact is that I cant INSERT a record from with an
    ending space. And, the problem is that that record insertion must depend on a
    form field....

    Feudalism Guest

  5. #4

    Default Re: final blank space

    So what you are saying is that you can insert the value successfully using your
    database IDE, but if you perform the same insert in your CFM page, using form
    fields, it trims the last space?

    And that if you output the length of the form field before your insert it
    displays a length of (3)

    BEFORE INSERT: <CFOUTPUT>#Len(form.yourField)#</CFOUTPUT>

    ... but when you run another query to get the new value it returns a length of
    (2)?

    AFTER INSERT: <CFOUTPUT>#Len(queryGetNewValue.theValueColumn)# </CFOUTPUT>

    mxstu Guest

  6. #5

    Default Re: final blank space

    I cant even insert using the database IDE !

    :S
    Feudalism Guest

  7. #6

    Default Re: final blank space

    .... " Ok, that works perfect to select the records that end with a blankspace,
    like " abcd " or " myself ". The fact is that I cant INSERT a record from with
    an ending space"

    Now I'm confused ;-) This sounds like your database DOES contain some values
    with spaces at the end. If you cannot insert values with a space at the
    end...through CF or through your database IDE, how did those values get into
    the database?

    mxstu Guest

  8. #7

    Default Re: final blank space

    Actually there is 0 registers that contains end spaces strings.

    That's because I cant find a way to insert them there! :(

    Using Word, for example, you can "search and replace" the string " ? " for the
    string " a ". It's a simple process, but I cant make it run in a CF environment
    with dynamically fed words, because I cant insert those strings in the database.

    In brief:
    I CAN use a replace function with a blankspace ended string.
    I CAN NOT insert an blankspace ended string in a database.

    Thankx

    Feudalism Guest

  9. #8

    Default Re: final blank space

    If you are not trimming the values in your code, then I would suspect that
    maybe a database setting is trimming the trailing spaces... except that you
    said it DOES maintain the space before the "?". Only the last space that is
    removed. Usually, a database setting that trims values will remove both
    spaces.

    1) What database are you using?
    2) Are you sure you are not trimming the values in your code?
    3) I would create a test table and run the following code, to pin-point where
    the problem is...

    Let me know what results you get when you run the test form



    <!--- Step 1: Create a test table --->
    CREATE TABLE testCharacterLength(
    id int identity(1,1),
    testCharacter varchar(50),
    testCharacterLen int
    )


    <!--- Step 2: Save this code as a CFM page and submit the form --->
    <cfoutput>
    <form action="#CGI.SCRIPT_NAME#" method="post">
    <input type="text" name="testCharacter" value=" ? ">
    <input type="submit">
    </form>
    </cfoutput>

    <cfif IsDefined("form.testCharacter")>
    <cfquery name="testInsert" datasource="#yourDSN#">
    SET ANSI_PADDING OFF
    INSERT INTO testCharacterLength (testCharacter, testCharacterLen)
    VALUES ('#form.testCharacter#', #Len(form.testCharacter)#)
    </cfquery>
    <cfquery name="getTestValue" datasource="#yourDSN#">
    SELECT TOP 1 testCharacter, testCharacterLen
    FROM testCharacterLength
    ORDER BY ID DESC
    </cfquery>
    <cfoutput>
    Form variable = [#form.testCharacter#]<br>
    Form variable len = #Len(form.testCharacter)#<br>
    <cfdump var="#getTestValue#">
    </cfoutput>
    </cfif>

    <!--- Step 3: Review the values --->

    mxstu Guest

  10. #9

    Default Re: final blank space

    Im using a mySQL database, and Im not trimming in the code.

    Ill test your code ASAP. Thanx.
    Feudalism Guest

  11. #10

    Default Re: final blank space

    You may need to change the syntax. The code was written for SQL Server. I do not think mySQL supports
    - SET ANSI_PADDING OFF (remove this line)
    - IDENTITY (change to the mySQL equivalent)

    mxstu Guest

  12. #11

    Default Re: final blank space

    Well, it seems like this trimming is by design for some versions of mySQL.
    Apparently it just trims the spaces on the end and not the front. If you are
    using an early version, you may need to use another datatype if you need to
    preserve the spaces.

    From documentation:

    "VARCHAR values are not padded when they are stored. Handling of trailing
    spaces is version-dependent. As of MySQL 5.0.3, trailing spaces are retained
    when values are stored and retrieved, in conformance with standard SQL. Before
    MySQL 5.0.3, trailing spaces are removed from values when they are stored into
    a VARCHAR column; this means the spaces also are absent from retrieved values.
    .....

    Before MySQL 5.0.3, if you need a data type for which trailing spaces are not
    removed, consider using a BLOB or TEXT type. Also, if you want to store binary
    values such as results from an encryption or compression function that might
    contain arbitrary byte values, use a BLOB column rather than a CHAR or VARCHAR
    column, to avoid potential problems with trailing space removal that would
    change data values."

    [url]http://dev.mysql.com/doc/mysql/en/char.html[/url]

    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139