Announcement

Collapse
No announcement yet.

Retrieving database fields

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

    Retrieving database fields



    The file dbAlias has a field labeled DESCRIP. The contents of that field in
    record 2 is Snowman.
    Here is a snippet of code:
    <MvASSIGN name="dbFld" Value="d.descrip">
    <MvOPEN
    NAME=dbAlias
    DATABASE=dbLoc $ dbN $ ".dbf"
    TYPE="xbase3">
    <MvGO NAME=dbAlias ROW="2">
    <MvASSIGN name="tmp" value="{dbFld}">


    Field Descrip=<MvEVAL EXPR="{tmp}"></p>

    What is printed is: Field Descrip=d.descrip
    The Code below produces the correct result:

    <MvOPEN
    NAME=dbAlias
    DATABASE=dbLoc $ dbN $ ".dbf"
    TYPE="xbase3">
    <MvGO NAME=dbAlias ROW="2">
    <MvASSIGN name="tmp" value="{d.descrip}">


    Field Descrip=<MvEVAL EXPR="{tmp}"></p>

    Anybody know WHY the first does not work?

    Dan Sweger
    [email protected]



    #2
    Retrieving database fields



    You may also want to try the following function:

    miva_variable_value
    (varname)

    Takes a variable name and returns the value of the variable to which the value of varname is referring.

    I've used it before and got the reference info from <A HREF =/"http://www.miva.com/docs/ScriptGuide_html/ScriptGuide.html#496882 in the system functions section/">http://www.miva.com/docs/ScriptGuide...de.html#496882 in the system functions section</A>.

    ps: sorry I forgot to send my last reply to the list

    --
    Andrew Rosborough
    <A HREF ="http://www.rosborough.net">http://www.rosborough.net</A>


    > just a quick glance, but it looks like the line:
    >
    > <MvASSIGN name="dbFld" Value="d.descrip"> is assigning dbFld the string value
    > "d.descrip". To get it to work you would have to include the eval brackets, '{'
    > and '}'.
    >
    > <MvASSIGN name="dbFld" Value="{d.descrip}">
    >
    > Hope that explains things for you.
    >
    > --
    > Andrew Rosborough
    > <A HREF ="http://www.rosborough.net">http://www.rosborough.net</A>
    >
    >
    > > The file dbAlias has a field labeled DESCRIP. The contents of that field in
    > > record 2 is Snowman.
    > > Here is a snippet of code:
    > > <MvASSIGN name="dbFld" Value="d.descrip">
    > > <MvOPEN
    > > NAME=dbAlias
    > > DATABASE=dbLoc $ dbN $ ".dbf"
    > > TYPE="xbase3">
    > > <MvGO NAME=dbAlias ROW="2">
    > > <MvASSIGN name="tmp" value="{dbFld}">
    > >

    Field Descrip=<MvEVAL EXPR="{tmp}"></p>
    > >
    > > What is printed is: Field Descrip=d.descrip
    > > The Code below produces the correct result:
    > >
    > > <MvOPEN
    > > NAME=dbAlias
    > > DATABASE=dbLoc $ dbN $ ".dbf"
    > > TYPE="xbase3">
    > > <MvGO NAME=dbAlias ROW="2">
    > > <MvASSIGN name="tmp" value="{d.descrip}">
    > >

    Field Descrip=<MvEVAL EXPR="{tmp}"></p>
    > >
    > > Anybody know WHY the first does not work?
    > >
    > > Dan Sweger
    > > [email protected]
    > >
    > >

    Comment


      #3
      Retrieving database fields



      Hi,

      On your first MvAssign, use the {}

      to look as
      <MvASSIGN name="dbFld" Value="{d.descrip}">

      Kevin


      -----Original Message-----
      From: [email protected] [mailto:[email protected]]On
      Behalf Of Dr. Daniel M. Sweger
      Sent: Monday, February 14, 2005 3:06 PM
      To: [email protected]
      Subject: [meu] Retrieving database fields


      The file dbAlias has a field labeled DESCRIP. The contents of that field in
      record 2 is Snowman.
      Here is a snippet of code:
      <MvASSIGN name="dbFld" Value="d.descrip">
      <MvOPEN
      NAME=dbAlias
      DATABASE=dbLoc $ dbN $ ".dbf"
      TYPE="xbase3">
      <MvGO NAME=dbAlias ROW="2">
      <MvASSIGN name="tmp" value="{dbFld}">


      Field Descrip=<MvEVAL EXPR="{tmp}"></p>

      What is printed is: Field Descrip=d.descrip
      The Code below produces the correct result:

      <MvOPEN
      NAME=dbAlias
      DATABASE=dbLoc $ dbN $ ".dbf"
      TYPE="xbase3">
      <MvGO NAME=dbAlias ROW="2">
      <MvASSIGN name="tmp" value="{d.descrip}">


      Field Descrip=<MvEVAL EXPR="{tmp}"></p>

      Anybody know WHY the first does not work?

      Dan Sweger
      [email protected]


      Comment


        #4
        Re: Retrieving database fields



        Thanks to all who replied. The function miva_variable_value worked just fine. Scot, thanks for your comments on scoping variables, but I was trying all various combinations and got sloppy.


        Scot Ranney [email protected] Wrote:
        >
        >The reason it won't work is because the variable, dbFld contains the
        >value "d.descrip". In fact, the snippet is working perfectly as
        >intended by mivascript.
        >
        >If you want it to work the way I think you do, then you will need to use
        >the built in function miva_variable_value() like this:
        >
        ><MvASSIGN name="tmp" value="{miva_variable_Value(dbFld)}">
        >
        >Now, I can't help but make some remarks about your code.
        >
        >Hardly any of your attribute values have double quotes around them, and
        >your variables are not scoped, and your database variable doesn't have
        >an alias.
        >
        >Here's how I would rewrite the first snippet so variables are scoped and
        >attribute syntax is correct (it will save you a lot of time in debugging
        >in the future if you do it "right")
        >
        >(assumming dbLoc and dbN are local variables)
        >
        ><MvASSIGN name="l.dbFld" Value="dbFld.d.descrip">
        ><MvOPEN
        > NAME="{ 'dbAlias' }"
        > DATABASE="{ l.dbLoc $ l.dbN $ '.dbf' }"
        > TYPE="xbase3">
        ><MvGO NAME="dbAlias" ROW="2">
        ><MvASSIGN name="l.tmp" value="{l.dbFld}">
        >

        Field Descrip=<MvEVAL EXPR="{l.tmp}"></p>
        >
        >Scot
        ><A HREF ="http://www.scotsscripts.com">http://www.scotsscripts.com</A>
        >
        >Dr. Daniel M. Sweger wrote:
        >> The file dbAlias has a field labeled DESCRIP. The contents of that field in
        >> record 2 is Snowman.
        >> Here is a snippet of code:
        >> <MvASSIGN name="dbFld" Value="d.descrip">
        >> <MvOPEN
        >> NAME=dbAlias
        >> DATABASE=dbLoc $ dbN $ ".dbf"
        >> TYPE="xbase3">
        >> <MvGO NAME=dbAlias ROW="2">
        >> <MvASSIGN name="tmp" value="{dbFld}">
        >>

        Field Descrip=<MvEVAL EXPR="{tmp}"></p>
        >>
        >> What is printed is: Field Descrip=d.descrip
        >> The Code below produces the correct result:
        >>
        >> <MvOPEN
        >> NAME=dbAlias
        >> DATABASE=dbLoc $ dbN $ ".dbf"
        >> TYPE="xbase3">
        >> <MvGO NAME=dbAlias ROW="2">
        >> <MvASSIGN name="tmp" value="{d.descrip}">
        >>

        Field Descrip=<MvEVAL EXPR="{tmp}"></p>
        >>
        >> Anybody know WHY the first does not work?
        >>
        >> Dan Sweger
        >> [email protected]
        >>
        >>
        >
        --
        From: Dan Sweger <[email protected]>

        Comment


          #5
          Retrieving database fields



          The reason it won't work is because the variable, dbFld contains the
          value "d.descrip". In fact, the snippet is working perfectly as
          intended by mivascript.

          If you want it to work the way I think you do, then you will need to use
          the built in function miva_variable_value() like this:

          <MvASSIGN name="tmp" value="{miva_variable_Value(dbFld)}">

          Now, I can't help but make some remarks about your code.

          Hardly any of your attribute values have double quotes around them, and
          your variables are not scoped, and your database variable doesn't have
          an alias.

          Here's how I would rewrite the first snippet so variables are scoped and
          attribute syntax is correct (it will save you a lot of time in debugging
          in the future if you do it "right")

          (assumming dbLoc and dbN are local variables)

          <MvASSIGN name="l.dbFld" Value="dbFld.d.descrip">
          <MvOPEN
          NAME="{ 'dbAlias' }"
          DATABASE="{ l.dbLoc $ l.dbN $ '.dbf' }"
          TYPE="xbase3">
          <MvGO NAME="dbAlias" ROW="2">
          <MvASSIGN name="l.tmp" value="{l.dbFld}">


          Field Descrip=<MvEVAL EXPR="{l.tmp}"></p>

          Scot
          <A HREF ="http://www.scotsscripts.com">http://www.scotsscripts.com</A>

          Dr. Daniel M. Sweger wrote:
          > The file dbAlias has a field labeled DESCRIP. The contents of that field in
          > record 2 is Snowman.
          > Here is a snippet of code:
          > <MvASSIGN name="dbFld" Value="d.descrip">
          > <MvOPEN
          > NAME=dbAlias
          > DATABASE=dbLoc $ dbN $ ".dbf"
          > TYPE="xbase3">
          > <MvGO NAME=dbAlias ROW="2">
          > <MvASSIGN name="tmp" value="{dbFld}">
          >

          Field Descrip=<MvEVAL EXPR="{tmp}"></p>
          >
          > What is printed is: Field Descrip=d.descrip
          > The Code below produces the correct result:
          >
          > <MvOPEN
          > NAME=dbAlias
          > DATABASE=dbLoc $ dbN $ ".dbf"
          > TYPE="xbase3">
          > <MvGO NAME=dbAlias ROW="2">
          > <MvASSIGN name="tmp" value="{d.descrip}">
          >

          Field Descrip=<MvEVAL EXPR="{tmp}"></p>
          >
          > Anybody know WHY the first does not work?
          >
          > Dan Sweger
          > [email protected]
          >
          >

          Comment

          Working...
          X