Ajuda para usar exemplo da CONTRIB\MYSQL

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
ANDRIL
Usuário Nível 5
Usuário Nível 5
Mensagens: 1298
Registrado em: 06 Jul 2004 00:44
Contato:

Ajuda para usar exemplo da CONTRIB\MYSQL

Mensagem por ANDRIL »

Pessoal, surgiu uma necessidade de integrar um sistema com um Mysql hospedado em um site. Estou usando xHarbour 1.0.0 (SIMPLEX) e fui tentar usar os exemplos da CONTRIB\MYSQL e tentei compilar atraves do hbmake o exemplo testes.prg, que foi renomeado para andmysql.prg e nao consegui.
C:\xHWGUI\BCC55\BIN\ilink32 @makefile.lnk
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_HB_FUN_TMYSQLSERVER' referenced from C:\XHWGUI\XHAR
BOUR\CONTRIB\MYSQL\OBJ\ANDMYSQL.OBJ
meu makefile esta assim:

Código: Selecionar todos

-LC:\xHWGUI\BCC55\lib\obj;C:\xHWGUI\BCC55\lib;C:\xHWGUI\xharbour\lib -Gn -M -m -s -Tpe -x -ap +
c0x32.obj obj\ANDMYSQL.obj, +
andmysql.exe,, +
lang.lib vm.lib rtl.lib rdd.lib macro.lib pp.lib dbfntx.lib dbfcdx.lib dbffpt.lib common.lib gtwin.lib codepage.lib ct.lib tip.lib pcrepos.lib hsx.lib hbsix.lib import32.lib cw32.lib, +
, +
Se coloco no hbmake a Mysql.lib da varios erros de referencia como o acima citado.

O arquivo fonte é o mesmo que esta na subpasta CONTRIB\MYSQL

Código: Selecionar todos

/*
 * $Id: testes.prg,v 1.1 2003/02/03 05:21:06 walito Exp $
 */

/*
 * xHarbour Project source code:
 * MySQL DBMS test program
 *
 * Copyright 2003 Walter Negro <anegro@overnet.com.ar>
 * www - http://www.xharbour.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
 *
 * As a special exception, the Harbour Project gives permission for
 * additional uses of the text contained in its release of Harbour.
 *
 * The exception is that, if you link the Harbour libraries with other
 * files to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the Harbour library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the Harbour
 * Project under the name Harbour.  If you copy code from other
 * Harbour Project or Free Software Foundation releases into a copy of
 * Harbour, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for Harbour, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.
 *
 */

#include "dbstruct.ch"

procedure main( )

   local aArg := {}, oServer, oQuery, oQuery2, oRow, i, aStru, cRow, aField
   local lDelTest := .f., server := "localhost", user := "root", password := ""

   SET CENTURY ON

   i := 1
   do while !empty( hb_argv( i ) )
      do case
      case hb_argv( i ) == "-d"
         lDelTest := .t.
      case hb_argv( i ) == "-s"
         server := hb_argv( ++i )
      case hb_argv( i ) == "-u"
         user := hb_argv( ++i )
      case hb_argv( i ) == "-p"
         password := hb_argv( ++i )
      endcase
      i++
   enddo

   oServer := TMySQLServer():New(server, user, password)
   if oServer:NetErr()
      Alert(oServer:Error())
   endif

   if !oServer:DBExist( "zoo" )
      oServer:CreateDatabase( "zoo" )
   endif

   oServer:SelectDB("zoo")

   dbUseArea(.T.,, 'animal', "animal", .F.)


   if "-d" IN cArg

      if oServer:TableExist( "test" )
         if oServer:DeleteTable("test")
            Alert("test deleted successfully")
         else
            Alert(oServer:Error())
         endif
      endif
   endif


   if oServer:TableExist( "test" )

      aStru := dbStruct()        // Cargo la estructura del dbf en un array

      for each aField in aStru
         if HB_EnumIndex() <= 2
            AADD( aField, .t. )  // Agrego una columna m s al array con
                                 // las definiciones de los dos primeros
                                 // campos, que indica que estas columnas
                                 // son NOT NULL. Esto es para poder incluirlas
                                 // como parte de la clave primaria.
         else
            exit
         endif
      next

      // Creo una tabla llamada "test", con la estructura contenida en aStru
      // y le indico que las columnas NAME y OWNER son clave primaria.
      //
      if oServer:CreateTable("test", aStru, "NAME,OWNER")
         Alert("test created successfully")
      else
         Alert(oServer:Error())
      endif

   endif


/*** Anulo esta parte porque no todos van a tener la tabla animal    ***
 *** creada, pero sirve a los fines did cticos de mostrar la lectura ***
 *** de una tabla de MySQL y el guardado de los datos en un dbf.     ***

   oQuery:=oServer:Query("SELECT * from animal", .f. )
//   oQuery:GetRow( oQuery:nCurRow )

   if oQuery:LastRec() > 0
      zap                  // Borramos todos los registros de la dbf
                           // para comenzar nuevamente el test.
      do while !oQuery:eof() .and. inkey()#-99
         append blank

//         replace name       with oQuery:FieldGet( oQuery:FieldPos( "NAME" ) )
//         replace owner      with oQuery:FieldGet( oQuery:FieldPos( "OWNER" ) )
//         replace species    with oQuery:FieldGet( oQuery:FieldPos( "SPECIES" ) )
//         replace sex        with oQuery:FieldGet( oQuery:FieldPos( "SEX" ) )
//         replace birth      with oQuery:FieldGet( oQuery:FieldPos( "BIRTH" ) )
//         replace death      with oQuery:FieldGet( oQuery:FieldPos( "DEATH" ) )

         // Ver n que esta forma de escribir es mucho m s legible
         // que la de arriba.
         // Lo que est  haciendo es cargar en la dbf los datos de la
         // tabla animal que est  en el server de MySQL
         //
         replace name       with oQuery:NAME
         replace owner      with oQuery:OWNER
         replace species    with oQuery:SPECIES
         replace sex        with oQuery:SEX
         replace birth      with oQuery:BIRTH
         replace death      with oQuery:DEATH

         oQuery:skip()

      enddo
   endif

*/

   animal->(dbgotop())

   while !animal->(eof())

      oQuery2 := oServer:Query("SELECT * from test where NAME='" + animal->NAME + "' and OWNER='" + animal->OWNER + "'", .f. )

      WITH OBJECT oQuery2         // This generate a "cache" of this object
                                  // that permit access more quickly than using
                                  // oQuery2:..., and it's more readable.
         :GetRow()

         ? animal->name,"|",animal->owner,"*"

         if :LastRec() > 0

            ? " --> modification of data <--"

            // En esta rutina, estamos actualizando los datos de la tabla
            // en el server. Cuando encontramos un dato que existe en el dbf
            // y en la tabla, lo actualizamos.

/*
            oRow := :GetRow()

            oRow:FieldPut(oRow:FieldPos("SPECIES"), animal->SPECIES)
            oRow:FieldPut(oRow:FieldPos("SEX"),     animal->SEX)
            oRow:FieldPut(oRow:FieldPos("BIRTH"),   animal->BIRTH)
            oRow:FieldPut(oRow:FieldPos("DEATH"),   animal->DEATH)

            if !:Update(oRow)       // Orden de actualizar los datos
                                    // del registro contenido en oRow.
               Alert(:Error())
            endif
*/

            // Otra vez tenemos una muestra de como es mucho m s legible
            // esta forma de acceder a los datos. Esta vez el ejemplo es
            // a la hora de guardar los datos en la tabla de MySQL.
            // Arriba, la forma anterior. Que por compatibilidad se mantiene.
            //
            :SPECIES    := animal->SPECIES
            :SEX        := animal->SEX
            :BIRTH      := animal->BIRTH
            :DEATH      := animal->DEATH

            if !:Update()           // Orden de actualizar los datos
                                    // del registro actual.
               Alert(:Error())
            endif

         else

            ? " --> append of data <--"

            // En esta otra parte, estamos agregando los datos que no
            // existen en la tabla "test".

/*
            // La forma de trabajo con oRow, no est  descartada y no es obsoleta.
            // Es otra forma de hacer las cosas.
            // Usar oRow sirve para tener varios registros podriamos decir
            // "cacheados", para evitar tener que movernos hasta ellos para
            // verlos o modificarlos.
            // Tambi‚n sirve para modificar o dar de alta unos cuantos registros
            // y luego volcarlos en otra rutina a todos juntos en el server.
            // A£n no est  implementado el acceso a oRow con el formato
            // oRow:NAME, como s¡ se puede usar oQuery:NAME.
            // Las ventajas que ten¡a el uso de oRow, eran que permit¡an un
            // acceso m s r pido a los datos en especial en listados, ya que
            // los campos pod¡an ser accedidos de la forma oRow:aRow[n].
            // Ahora tambi‚n es posible hacer oQuery:aRow[n].

            oRow := :GetBlankRow()

            ? "FieldPos(Name)",oRow:FieldPos("NAME")

            oRow:FieldPut(oRow:FieldPos("NAME"),    animal->NAME)
            oRow:FieldPut(oRow:FieldPos("OWNER"),   animal->OWNER)
            oRow:FieldPut(oRow:FieldPos("SPECIES"), animal->SPECIES)
            oRow:FieldPut(oRow:FieldPos("SEX"),     animal->SEX)
            oRow:FieldPut(oRow:FieldPos("BIRTH"),   animal->BIRTH)
            oRow:FieldPut(oRow:FieldPos("DEATH"),   animal->DEATH)

            if !:Append(oRow)       // Orden de agregar (INSERT) los
                                    // datos del registro en oRow.
               Alert(:Error())
            endif
*/

            :GetBlankRow( )

            :NAME       := animal->NAME
            :OWNER      := animal->OWNER
            :SPECIES    := animal->SPECIES
            :SEX        := animal->SEX
            :BIRTH      := animal->BIRTH
            :DEATH      := animal->DEATH


            if !:Append()           // Orden de agregar (INSERT) los
                                    // datos del registro actual.
               Alert(:Error())
            endif

         endif
      END // WITH

      animal->(dbSkip())

   enddo


   animal->(dbCloseArea())

   oServer:Destroy()
return
Alguem sabe o porque do erro?
Abraços
Clipper 5.2e / Blinker 5.1 / Harbour 3.2 / GTwvg
jamazevedo
Usuário Nível 3
Usuário Nível 3
Mensagens: 122
Registrado em: 29 Dez 2005 16:50
Localização: Manaus - AM

Ajuda para usar exemplo da CONTRIB\MYSQL

Mensagem por jamazevedo »

Estou usando o Harbour 2.1.0 e os exemplos funcionam.
Fui além e estou usando um aplicação 100% mysql.
______________________________________________________
Usando: Linux Ubuntu 18.04, Harbour 3.2.0dev r1811161533
______________________________________________________
José Airton de Menezes Azevedo
Manaus - AM
marcos.gurupi
Usuário Nível 4
Usuário Nível 4
Mensagens: 939
Registrado em: 06 Jul 2004 11:53
Localização: Gurupi-TO

Ajuda para usar exemplo da CONTRIB\MYSQL

Mensagem por marcos.gurupi »

Caro, se for possivel seria de grande ajuda para todos que querem tb usar o MYSQL da CONTRIB vc postar exemplos do uso.

Marcos Roberto.
Marcos Roberto
NetService Software
lugab
Colaborador
Colaborador
Mensagens: 843
Registrado em: 19 Mai 2009 15:58

Ajuda para usar exemplo da CONTRIB\MYSQL

Mensagem por lugab »

Algum tempo atrás, usavndo o xharbour 1.0, eu tentei usar o exemplo citado pelo Marcos, mas desisti face os mesmos problemas q ele ta enfrentando.
lugab
jamazevedo
Usuário Nível 3
Usuário Nível 3
Mensagens: 122
Registrado em: 29 Dez 2005 16:50
Localização: Manaus - AM

Ajuda para usar exemplo da CONTRIB\MYSQL

Mensagem por jamazevedo »

Estou postando um exemplo aqui porque pedirão, porém considero que o problema esteja na versão do xHarbour.
Utilizo: Harbour 2.1.0 em Linux Ubuntu 10.04

Fonte: exemplosql.prg

Código: Selecionar todos

#DEFINE id_CRLF     CHR( 13 ) + CHR( 10 )
#DEFINE id_SERVER   "localhost"
#DEFINE id_USER     "root"
#DEFINE id_PASSWORD "root123"

FUNCTION  Main()
          LOCAL oServer     := TMySQLServer():New( id_SERVER, id_USER, id_PASSWORD )
          LOCAL oBancoDados , oTabela , oRow
          LOCAL nConta1 , nConta2 , nConta3
          LOCAL nLen1   , nLen2   , nLen3
          oBancoDados := oServer:Query( "SHOW DATABASES;" )
          IF oBancoDados:NetErr()
             ALERT( oBancoDados:Error() )
          ELSE
             nLen1 := oBancoDados:LastRec()
             FOR nConta1 = 1 TO nLen1
                 oRow := oBancoDados:GetRow( nConta1 )
                 ? oRow:FieldGet( 1 )
             NEXT
             oTabela := oServer:Query( "SELECT * FROM mysql.user;" )
             IF oTabela:NetErr()
                ALERT( oTabela:Error() )
             ELSE
                nLen2 := oTabela:LastRec()
                FOR nConta2 = 1 TO nLen2
                    oRow := oTabela:GetRow( nConta2 )
                    ? oRow:FieldGet( 1 ) , oRow:FieldGet( 2 )
                NEXT
             ENDIF
          ENDIF
          oTabela:Destroy()
          oBancoDados:Destroy()
          oServer:Destroy()
RETURN    NIL
Arquivo de Compilação: exemplosql.hbp

Código: Selecionar todos

# compila so os alterados
-inc
-w1
-lhbmysql       // esta lib é gerada na pasta Contrib
-lmysqlclient  // esta lib é instalada junto com os pacotes do MySql

# nome do executavel
-oexemplosql

# fontes que serao compilados e lincados
exemplosql.prg
______________________________________________________
Usando: Linux Ubuntu 18.04, Harbour 3.2.0dev r1811161533
______________________________________________________
José Airton de Menezes Azevedo
Manaus - AM
Responder