ejemplo con postgresql

ejemplo con postgresql

Postby Miguel Salas » Tue Apr 06, 2010 11:36 pm

Hola.
He estado analizando hacia que bd migrar mi aplicación, he decidido jugarmela con postgres, para lo que necesito si tienen un ejemplo practico para accesar, grabar, modificar, etc. , o es que tambien tengo que cambiar el lenguaje?
saludos
Miguel Salas
 
Posts: 132
Joined: Sun Oct 23, 2005 4:09 pm
Location: Pánuco,Ver. México

Re: ejemplo con postgresql

Postby Lautaro » Thu Apr 08, 2010 4:13 pm

Hola Miguel,

Antes de responderte, unas consultas :

- ¿ Como te vas a conectar a postgres ? , con driver nativo ( existe en harbour una serie de clases que estan operando ), con Ado, usando el driver odbc o algun dbprovider.

- ¿ Que usas para programar ? harbour o xharbour


Yo uso harbour y para el driver nativo puedes ver los ejemplos en hbpgsql , si vas a usar ado, en este foro puedes usar cualquier ejemplo sobre eso y solo tienes que cambiar la cadena de coneccion.

Espero haberte ayudado un poco,

Lautaro Moreira
User avatar
Lautaro
 
Posts: 322
Joined: Fri Oct 07, 2005 2:44 pm
Location: Osorno, Chile

Re: ejemplo con postgresql

Postby Miguel Salas » Mon Apr 12, 2010 2:15 pm

Hola Lautaro

Tengo Fivewin-xHarbour con dbf actualmente
En cuanto a la conexion , no tengo experiencia en base de datos, mi intención es poner mi aplicacion en Cliente/Servidor, he visto que con postgres usando SQLRDD, la pregunta va mas enfocada a que alguien que tenga corriendo una aplicacion con fivewin y postgres y algun ejemplo del manejo de tablas.
gracias
Miguel Salas
 
Posts: 132
Joined: Sun Oct 23, 2005 4:09 pm
Location: Pánuco,Ver. México

Re: ejemplo con postgresql

Postby russimicro » Sat Apr 17, 2010 4:21 pm

#include "sqlrdd.ch"
#include "mysql.ch"


#define RECORDS_IN_TEST 1000
#define SQL_DBMS_NAME 17
#define SQL_DBMS_VER 18

REQUEST SQLRDD, SR_MYSQL

/*------------------------------------------------------------------------*/

Function Main( cDSN, lLog )

local apCode, oSqlCon , oRddCon , oSqlRdd, oSqlWeb
local nCnn, i



//***INICIO CONEXION CON DB CON POSTGRES SQLRDD

? "Connecting to database SQLRDD...postgres"

cConnString1 := "PGS=192.168.2.11;UID=user_comparta;PWD=123;DTB=xhb"

oSqlRdd := ConectaSqlRdd(cConnString1)

SR_GetConnection( oSqlRdd )

? "Connected to SQLRDD :", SR_GetConnectionInfo(, SQL_DBMS_NAME ), SR_GetConnectionInfo(, SQL_DBMS_VER )

USE "TEST_TABLE" EXCLUSIVE VIA "SQLRDD" NEW ALIAS TEST

BROWSE()

// CODIFIQUE IGUAL QUE CON DBF...

//***FIN CONEXION CON DB CON POSTGRES


*/

//***INICIO CONEXION CON DB CON MYSQL NO SQLRDD

? "Connecting to database NO SQLRDD...mysql"

cConnString2 := "MySQL=200.00.888.121;UID=user_zerus;PWD=123;DTB=db_zerus"

oSqlWeb := ConectaSqlRdd(cConnString2)

oSql := SR_GetConnection( oSqlWeb )

? "Connected to NO SQLRDD :", SR_GetConnectionInfo(, SQL_DBMS_NAME ),SR_GetConnectionInfo(, SQL_DBMS_VER )


apCode := SR_SQLParse( "SELECT * FROM personas WHERE ccodigocli = ?")

cSql := SR_SQLCodeGen( apCode,{"1"}, oSql:nSystemID )

osql:exec(cSql,,.t.,,'arquivo.dbf','temp') // ...ok

//aRet:={}
//osql:exec(cSql,,.t.,@aret) // ..OK
// alert( len(aRet) )

// use (csql) shared new alias temp via "SQLRDD" // ...ok

sele temp
browse(5,5,20,75)

apCode := SR_SQLParse( "UPDATE personas SET cnombrecli = ? WHERE ccodigocli = ?")
oSql := SR_GetConnection( oSqlWeb )
cSql := SR_SQLCodeGen( apCode,{"la juana VALENTINA 4","1"}, oSql:nSystemID )
osql:exec(cSql)

temp->( DBCOMMIT() )


TEMP->( DBGOTOP() )

DO WHILE TEMP->( !EOF() )

? TEMP->CNOMBRECLI

TEMP->( DBSKIP() )
ENDDO

INKEY(0)


CLOSE ALL

// CODIFIQUE IGUAL QUE CON DBF...

//***FIN CONEXION CON DB CON MYSQL NO SQLRDD

Return NIL

*******************************************************************************************

FUNCTION ConectaSqlRdd(cConnString)

LOCAL nDetected

nDetected := DetectDBFromDSN( cConnString )

If nDetected > SYSTEMID_UNKNOW

oCon := SR_AddConnection( nDetected, cConnString )

ELSE

alert("Error de conexi¢n")

return -1

EndIf

If oCon < 0

alert("Error al conectarse a la base de datos de MySql : " )
CLS
Quit

EndIf

return oCon

**************************************************



#include "connect.prg"

/* IMPORTANT: THIS FILE IS NOT TO BE USED DIRECTLY. YOU SHOULD INCLUDE IT IN PROPER APPLICATION PRG FILE
AS SHOWN IN DEMO01.PRG, PARSER2.PRG, MEMO.PRG, ETC., AND CALL CONNECT() FUNCTION.
*/

/*
* SQLRDD connection
* Sample applications connect routine
* Copyright (c) 2005 - Marcelo Lombardo <lombardo@uol.com.br>
* All Rights Reserved
*/

#include "pgs.ch" // Needed if you plan to use native connection to Postgres
#include "mysql.ch" // Needed if you plan to use native connection to MySQL
#include "oracle.ch" // Needed if you plan to use native connection to Oracle
#include "firebird.ch" // Needed if you plan to use native connection to Firebird

REQUEST SQLRDD // SQLRDD should be linked in
REQUEST SR_ODBC // Needed if you plan to connect with ODBC
REQUEST SR_PGS // Needed if you plan to use native connection to Postgres
REQUEST SR_MYSQL // Needed if you plan to use native connection to MySQL
REQUEST SR_ORACLE // Needed if you plan to use native connection to Oracle
REQUEST SR_FIREBIRD // Needed if you plan to use native connection to Firebird

REQUEST DBFNTX
REQUEST DBFCDX
REQUEST DBFFPT
REQUEST DBFDBT

/*------------------------------------------------------------------------*/

Function Connect( cDatabase )

local nCnn, nDrv, cDriver, nOpt, nDetected, hIniFile, aKeys, nKey, cConnString
local oldScreen, hDsn

SetMode( 35, 80 )

hIniFile := HB_ReadIni( "sqlrdd.ini", .F.,,.F. ) // Read ini file in a hash table

If hIniFile == NIL
? "Could not read from sqlrdd.ini"
Quit
EndIf

If cDatabase == NIL
aKeys := HGetKeys( hIniFile )
If len(aKeys) == 0
? "No connections available in sqlrdd.ini"
Quit
ElseIf len(aKeys) == 1
nKey := 1
Else
clear screen
@5,1 say PadC( "Choose connection option", 80 )
nKey := achoice( 5, 20, 22, 60, aKeys )
clear screen

If nKey == 0
? "No connection selected"
Quit
EndIf
EndIf

hDsn := HGetValueAt( hIniFile, nKey )

If !"CONNSTRING" IN hDsn
? "ConnString not found in " + aKeys[nKey]
Quit
EndIf
Else
If ! cDatabase IN hIniFile
? "Connection [" + cDatabase + "] not found in sqlrdd.ini"
Quit
EndIf

hDsn := hIniFile[ cDatabase ]

If !"CONNSTRING" IN hDsn
? "ConnString not found in " + cDatabase
Quit
EndIf

EndIf

cConnString := hDsn[ "CONNSTRING" ]
nDetected := DetectDBFromDSN( cConnString )

If nDetected > SYSTEMID_UNKNOW
? "Connecting to", cConnString
nCnn := SR_AddConnection( nDetected, cConnString )
Else
clear screen
nOpt := Alert( "Please, select connection type", { "ODBC", "Postgres", "MySQL", "Oracle", "Firebird" } )
If nOpt > 0
nCnn := SR_AddConnection( If( nOpt = 1, CONNECT_ODBC, if( nOpt = 2, CONNECT_POSTGRES, if( nOpt = 3, CONNECT_MYSQL, if( nOpt = 4, CONNECT_ORACLE, CONNECT_FIREBIRD ) ) ) ), cConnString )
Else
? "No connection type selected"
Quit
EndIf
EndIf

/* returns the connection handle or -1 if it fails */
If nCnn < 0
? "Connection error. See sqlerror.log for details."
Quit
EndIf

Return .T.

/*------------------------------------------------------------------------*/
russimicro
 
Posts: 225
Joined: Sun Jan 31, 2010 3:30 pm
Location: Bucaramanga - Colombia


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests