Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Not sure how to handle this sort of speaking FoxPro DBF

Not sure how to handle this sort of speaking FoxPro DBF

Scheduled Pinned Locked Moved Database
algorithmshelptutorialannouncement
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    This Foxpro program keeps using spaces on the invoice number column in front or the data. Perhaps that was the norm back then before I started programming E.G. "70155" would be " 70155" So I not sure if the column is fixed, or if every invoice number starts with a " " blank space. e.g. " 155" I wrote this placing a space in front of the invoice number, but afraid it may backfire on me when the invoice number grows larger

    Dim c5 As New System.Data.OleDb.OleDbCommand("UPDATE ARTRS01H.dbf SET FPRICE = 0.00 WHERE FINVNO = ' " & pFINVNO & "' AND FITEMNO = '" & pFITEMNO & "'", connection)

    I thought using a wildcard, but I've been searching for a couple of hours and cant get things like $,% to work

    If it ain't broke don't fix it

    J 1 Reply Last reply
    0
    • J jkirkerx

      This Foxpro program keeps using spaces on the invoice number column in front or the data. Perhaps that was the norm back then before I started programming E.G. "70155" would be " 70155" So I not sure if the column is fixed, or if every invoice number starts with a " " blank space. e.g. " 155" I wrote this placing a space in front of the invoice number, but afraid it may backfire on me when the invoice number grows larger

      Dim c5 As New System.Data.OleDb.OleDbCommand("UPDATE ARTRS01H.dbf SET FPRICE = 0.00 WHERE FINVNO = ' " & pFINVNO & "' AND FITEMNO = '" & pFITEMNO & "'", connection)

      I thought using a wildcard, but I've been searching for a couple of hours and cant get things like $,% to work

      If it ain't broke don't fix it

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      This works at the moment, I'll run with it today

      Dim c3 As New System.Data.OleDb.OleDbCommand("UPDATE ARTRS01.dbf SET FPRICE = " & pFPRICE & ", FAMOUNT = " & pFPRICE & " WHERE FINVNO LIKE '%" & pFINVNO & "%' AND FITEMNO = '" & pFITEMNO & "'", connection)

      If it ain't broke don't fix it

      L Richard DeemingR 2 Replies Last reply
      0
      • J jkirkerx

        This works at the moment, I'll run with it today

        Dim c3 As New System.Data.OleDb.OleDbCommand("UPDATE ARTRS01.dbf SET FPRICE = " & pFPRICE & ", FAMOUNT = " & pFPRICE & " WHERE FINVNO LIKE '%" & pFINVNO & "%' AND FITEMNO = '" & pFITEMNO & "'", connection)

        If it ain't broke don't fix it

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Pad left (with blanks) all compared fields to their "defined lengths" (i.e. what's defined in the dbf), and then compare those. That's your safest route (IMO).

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        J 1 Reply Last reply
        0
        • J jkirkerx

          This works at the moment, I'll run with it today

          Dim c3 As New System.Data.OleDb.OleDbCommand("UPDATE ARTRS01.dbf SET FPRICE = " & pFPRICE & ", FAMOUNT = " & pFPRICE & " WHERE FINVNO LIKE '%" & pFINVNO & "%' AND FITEMNO = '" & pFITEMNO & "'", connection)

          If it ain't broke don't fix it

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^] How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^] Query Parameterization Cheat Sheet | OWASP[^]

          Using c3 As New System.Data.OleDb.OleDbCommand("UPDATE ARTRS01.dbf SET FPRICE = @FPRICE, FAMOUNT = @FAMOUNT WHERE FINVNO LIKE '%' + @FINVNO + '%' AND FITEMNO = @FITEMNO", connection)
          c3.Parameters.AddWithValue("@FPRICE", pFPRICE)
          c3.Parameters.AddWithValue("@FAMOUNT", pFPRICE)
          c3.Parameters.AddWithValue("@FINVNO", pFINVNO)
          c3.Parameters.AddWithValue("@FITEMNO", pFITEMNO)
          ...
          End Using

          Also, be very wary of your LIKE clause. If your pFINVNO is, for example, "1", your query will update every record where the FINVNO column contains 1, including '10', '21', '123456', etc.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          J 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^] How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^] Query Parameterization Cheat Sheet | OWASP[^]

            Using c3 As New System.Data.OleDb.OleDbCommand("UPDATE ARTRS01.dbf SET FPRICE = @FPRICE, FAMOUNT = @FAMOUNT WHERE FINVNO LIKE '%' + @FINVNO + '%' AND FITEMNO = @FITEMNO", connection)
            c3.Parameters.AddWithValue("@FPRICE", pFPRICE)
            c3.Parameters.AddWithValue("@FAMOUNT", pFPRICE)
            c3.Parameters.AddWithValue("@FINVNO", pFINVNO)
            c3.Parameters.AddWithValue("@FITEMNO", pFITEMNO)
            ...
            End Using

            Also, be very wary of your LIKE clause. If your pFINVNO is, for example, "1", your query will update every record where the FINVNO column contains 1, including '10', '21', '123456', etc.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #5

            It started out using parameters, and it's a Windows App. But I wasn't able to match the parameters and started easter egg hunting to figure out why. Back to the case sensitive stuff and that extra blank char prefix. So I wrote it the old school way to diagnose it. I'll try and go back to parameters on that, but will have to use the ? in order for that. It's suppose to be more FoxPro than SQL, like speaking pure FoxPro using VFPOLEDB

            If it ain't broke don't fix it

            1 Reply Last reply
            0
            • L Lost User

              Pad left (with blanks) all compared fields to their "defined lengths" (i.e. what's defined in the dbf), and then compare those. That's your safest route (IMO).

              "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

              J Offline
              J Offline
              jkirkerx
              wrote on last edited by
              #6

              I have a width of 74 for that column. I'm not sure what the units are. I'll google it today.

              If it ain't broke don't fix it

              L 1 Reply Last reply
              0
              • J jkirkerx

                I have a width of 74 for that column. I'm not sure what the units are. I'll google it today.

                If it ain't broke don't fix it

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                What do you mean by "Google" it? The definition of the field is in the DBF; you can even determine that with code at run-time to make it generic.

                "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                J 1 Reply Last reply
                0
                • L Lost User

                  What do you mean by "Google" it? The definition of the field is in the DBF; you can even determine that with code at run-time to make it generic.

                  "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                  J Offline
                  J Offline
                  jkirkerx
                  wrote on last edited by
                  #8

                  I think the width was 74, just not sure 74 of what unit.

                  If it ain't broke don't fix it

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups