Buenos dias
Sigo avanzando, pero con algunas curiosidades ...
Con el pequeño ejemplo adjunto, he conseguido listar las tablas de una BD, saber si una tabla existe o crear una tabla y añadirle registros
El caso curioso es que me da error al abrir una tabla existente en la BD, que no ha creado directamente SQLRDD
- Code: Select all Expand view
Error SQLRDD/1001 Error Opening table in SQL database - RollBack executed.: TEST2 (DOS Error 2)
Called from SR_WORKAREA:RUNTIMEERR(1942)
Called from SR_WORKAREA:SQLOPENAREA(5962)
Called from DBUSEAREA(0)
Called from CREATETABLE(97)
Called from MAIN(72)
He comparado la creación de una tabla, por ejemplo desde HeidiSQL con la que crea SQLRDD y no le veo diferencias( permisos, codepage, etc)
También como curiosidad, los campos extendidos de las DBF, por ejemplo los autoincrementales {"ID", "+", 10,0 } producen error al ejecutar DbCreate(), PERO la buena noticia es que SQLRDD nos crea un campo autoincremental de forma automática, con su indice de clave primaria
Aqui dejo mi ejemplo, por si alguien quiere experimentar y contrastar lo que explico
- Code: Select all Expand view
/*
* SQLRDD Test
* Copyright (c) 2003 - Marcelo Lombardo <marcelo@xharbour.com.br>
* All Rights Reserved
*/
#include "sqlrdd.ch"
#define RECORDS_IN_TEST 1000
#define SQL_DBMS_NAME 17
#define SQL_DBMS_VER 18
REQUEST SQLRDD // SQLRDD should be linked in
REQUEST SQLEX // SQLRDD Extreme 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
/*------------------------------------------------------------------------*/
PROCEDURE main()
local nCnn, i
local cRDD, cConnString
local aFiles
RddSetDefault( "DBFCDX" )
// Las 2 cadenas funcionan de forma identica
cConnString := "MySQL=localhost;UID=root;PWD=1234;DTB=testdb"
cConnString := "Server=localhost; Port=3306; Database=testdb; Uid=root; Pwd=1234;"
SR_SETSQL2008NEWTYPES(.t.)
SR_SetMininumVarchar2Size( 2 )
SR_UseDeleteds(.f.)
SR_SetlUseDBCatalogs( .T. ) // Utilizar indices de la BD
? "Test SQLRDD"
? ""
? "Connecting to database..."
cRDD := "SQLRDD"
nCnn := SR_AddConnection( CONNECT_MYSQL, cConnString )
? "Connected to :", SR_GetConnectionInfo(, SQL_DBMS_NAME ), SR_GetConnectionInfo(, SQL_DBMS_VER )
? "RDD Version :", SR_Version()
? "RDD in use :", cRDD
? "ConnectionType :", SR_GetConnection():nConnectionType
cTable := "customer"
? "Exist Table "+ cTable, SR_ExistTable( cTable )
aFiles := SR_ListTables("testdb")
? "Tablas de la BD :", len(aFiles)
? "Lista de Tablas"
for each i in aFiles
// Descartar tablas de sistema
if ! left( i, 3 ) $ "SR_;TOP;SYS;DTP"
? i
endif
next
CreateTable( cRDD )
// Tablas creadas fuera del RDD fallan, error apertura !
// USE ( cTable ) VIA cRDD
// BROWSE()
RETURN
/*------------------------------------------------------------------------*/
PROCEDURE CreateTable( cRDD )
local nArea
local cTable := "test2"
local aStruct := {;
{"ID", "N", 10,0 },;
{"FIRST","C", 40,0 },;
{"LAST", "C", 40,0 },;
{"AGE", "N", 10,0 } ;
}
if ! SR_ExistTable( cTable )
? "Creating table :", dbCreate( cTable, aStruct, cRDD )
endif
USE ( cTable ) EXCLUSIVE VIA ( cRDD )
nArea := select()
( nArea )->( dbappend() )
( nArea )->ID := 1
( nArea )->FIRST := "Mark"
( nArea )->LAST := "Baley"
( nArea )->AGE := 39
( nArea )->( dbgotop() )
BROWSE()
RETURN
/*------------------------------------------------------------------------*/