FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Test if a Ms Access SQL field is Number
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Test if a Ms Access SQL field is Number
Posted: Thu Oct 25, 2012 01:30 PM

To All

How can I test if a Sql field is a character value type. I can test for the valtype of a variable assigned from a field is character, but if the table is empty there is no way to assign a field value to a variable to test its valtype ?

cName := oRs:Fields("Covered By Warranty"):Type .. returns the position of the field in the structure but not its valtype ..

Rick Lipkin

Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Test if a Ms Access SQL field is Number
Posted: Thu Oct 25, 2012 02:58 PM
Rick:

Long time ago I made this function perhaps these can help you

Code (fw): Select all Collapse
/*
* --------------------------------------------------------------------------*
* Lee las tablas y sus estructuras                                          *
* --------------------------------------------------------------------------*
*/
STATIC FUNCTION LeeTablas()
LOCAL oCat
LOCAL nVez, j

oCat = CREATEOBJECT( "ADOX.Catalog" )
oCat:ActiveConnection := oApp:oCon:ConnectionString

FOR nVez := 0 TO oCat:Tables:Count() - 1
    MsgInfo(oCat:Tables(nVez):Name)

    IF UPPER(ALLTRIM(oCat:Tables(nVez):Name)) == "PROYECTO"
        FOR j := 0 TO oCat:Tables(nVez):Columns:Count() - 1
            ? SPACE( 4 ) + oCat:Tables(nVez):Columns( j ):Name
            ? SPACE( 4 ) + STR(oCat:Tables(nVez):Columns( j ):Type,3,0)
            ? SPACE( 4 ) + STR(oCat:Tables(nVez):Columns( j ):DefinedSize,5,0)
            ? SPACE( 4 ) + STR(oCat:Tables(nVez):Columns( j ):Precision)
            ? SPACE( 4 ) + STR(oCat:Tables(nVez):Columns( j ):NumericScale)
        NEXT
    ENDIF

NEXT
/*
          NAME: Nombre del campo
      TYPE: 200 = VARCHAR, 133 = DATE, 201 = TEXT, 131 = DECIMAL
 DEFINEDSIZE: Longitud del campo, solo para tipos VARCHAR y TEXT
   PRECISION: Longitud del campo, solo para tipos DECIMAL
NUMERICSCALE: Número de decimales, solo para tipos NUMERIC y DECIMAL
*/
RETURN(NIL)


Best regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Test if a Ms Access SQL field is Number
Posted: Thu Oct 25, 2012 04:13 PM
Armando

Your code looks promising .. how did you create your connection ?

Code (fw): Select all Collapse
oCat:ActiveConnection := oApp:oCon:ConnectionString


Thanks
Rick Lipkin
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Test if a Ms Access SQL field is Number
Posted: Thu Oct 25, 2012 05:13 PM
Armando

I figured out the connection ..

Code (fw): Select all Collapse
oCn  := CREATEOBJECT( "ADODB.Connection" )

TRY
   oCn:Open( xCONNECT )
CATCH oErr
   Saying := "Could not open a Connection to Database "+xSource+chr(10)
   MsgInfo( Saying )
   RETURN(.F.)
END TRY

Try
  oCat:ActiveConnection := oCn
Catch
   Saying := "Could not open connection to ADOX"
   MsgInfo( Saying )
   Return(.f.)
End Try


The rest of your code worked perfectly !!

Thanks
Rick Lipkin
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Test if a Ms Access SQL field is Number
Posted: Thu Oct 25, 2012 06:45 PM
Rick:

Here is my conection code

Code (fw): Select all Collapse
TRY
    oApp:oCon   :=  TOleAuto():new("adodb.connection")
CATCH oError
    MsgStop( "No se ha podido crear la conexión al servidor !", oApp:cAplicacion)
    RETURN(.F.)
END

oApp:oCon:ConnectionString := ALLTRIM(oApp:cDriveName) + ;
                                        ";Server=" + ALLTRIM(oApp:cServer) + ;
                                        ";Port=" + ALLTRIM(oApp:cPort) + ;
                                        ";Database=" + ALLTRIM(oApp:cDataBase) + ;
                                        ";User=" + ALLTRIM(oApp:cUser)+;
                                        ";Password=" + ALLTRIM(oApp:cPassWord) + ;
                                        ";Option=3;"

TRY
    oApp:oCon:Open()
CATCH oError
    MsgInfo("No se pudo lograr la conexión al servidor, REVISE LA CONEXION DE SU RED O LA CONEXION A INTERNET !",oApp:cAplicacion)
    ShowError(oError)
    RETURN(.F.)
END


Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero

Continue the discussion