Ejemplo de Tdatarow para crear Base de datos y tablas

Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Wed Mar 15, 2017 1:44 pm

Buenos dias,

Alguien tendra un ejemplo de como crear base de datos y tablas con la Tdatarow?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Thu Mar 16, 2017 2:09 pm

Alguna sugerencia?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby nageswaragunupudi » Tue Mar 21, 2017 1:50 pm

The purpose of TDataRow is not for creating database or tables.
The class is used to read one row from a table of any kind of database for editing and saving.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10207
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Tue Mar 21, 2017 1:54 pm

Thanks

Which class is used to create Database and tables using ADO?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby nageswaragunupudi » Tue Mar 21, 2017 2:13 pm

Which database you want to use with ADO?
MySql ? Or MSSql?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10207
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Tue Mar 21, 2017 2:16 pm

MSSQl
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby nageswaragunupudi » Tue Mar 21, 2017 4:29 pm

First thing is to connect to the server. The server can be a remote server or SQLEXPRESS on local PC.
Please use this function to connect to the server. MSSQL Server/SQLEXPRESS can be configured
to accept logins as user/password or with Windows authentication or both. When configuring it is desirable to allow user/password based logins. For MSSQL server, built-in adiminstrator account's name is SA, like "root" for MySql.

Syntax:
oCn := FW_OpenAdoConnection( { "MSSQL", cServer, [cDataBase], cUser, cPassword }, lShowError )
OR
oCn := FW_OpenAdoConnection( { "MSSQL,cServer,[cDataBase],cUser,cPassword", lShowError )

When we are connecting for the first time we can ommit database name because we want to create a database after logging in.

Example:
Code: Select all  Expand view

oCn := FW_OpenAdoConnection( { "MSSQL", "PCNAME\SQLEXPRESS",,"SA","secret" }, .t. )
if oCn == nil
   ? "Connect Fail"
   return nil
endif

// proceed using the connection.
// Create a database named FWH

oCn:Execute( "CREATE DATABASE FWH" )
oCn:Close()
 


Now we can loging with the database name and start creating tables.
In this example, we copy a dbf file to the server to the database FWH, open the table and browse it
Code: Select all  Expand view

oCn := FW_OpenAdoConnection( { "MSSQL", "PCNAME\SQLEXPRESS","FWH","SA","secret" }, .t. )
if oCn == nil
   ? "Connect Fail"
   return nil
endif

FW_AdoImportFromDBF( oCn, "c:\fwh\samples\customer.dbf" )

oRs  := FW_OpenRecordSet( oCn, "customer" )
XBROWSER oRs FASTEDIT
oRs:Close()
oCn:Close()
 


We can continue with more examples depending on your requirements.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10207
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Tue Mar 21, 2017 5:11 pm

Thanks so much
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Wed Mar 29, 2017 12:51 pm

Hello

It is possible to create a wrapper function instead to write Fw_OpenAdoConnection to call it ? Some sample?

Regards
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Thu Mar 30, 2017 1:32 pm

This example is good but it just create Tables from DBF.

Another example to create it from code? The same for Database creation using CREATE DATABASE ?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby cnavarro » Thu Mar 30, 2017 1:39 pm

Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6498
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Thu Mar 30, 2017 1:44 pm

Thanks a lot!
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby nageswaragunupudi » Sat Apr 01, 2017 1:26 am

It is possible to create a wrapper function instead to write Fw_OpenAdoConnection to call it ?

FW_OpenAdoConnection() is itself a wrapper function. Using this function resolves many issues relating to construction of connection strings yourself.

Creating Database

oCn:Execute( "CREATE DATABASE <databasename>" )

Creating Table:
FWH provides easy and simpler function to create tables. You can use the same function create the same table in different RDBMs ( eg Access, MSSQL, MySql, Oracle ). Also FWH function works on those RDBMs which do not fully support ADOX.

FWAdoCreateTable( cTable, aStruct, oCn ) // aStruct is identical to DBSTRUCT()

Usage:
Code: Select all  Expand view

FWAdoCreateTable( "sales", { { BILLNO, 'N', 5, 0 }, ;
                                            { "DETAIL", "C", 20, 0 }, ;
                                            { "QTY", "N", 5, 0 }, ;
                                            { "RATE", "N", 5, 2 }, ;
                                            { "AMOUNT", "N", 12,2 } }, oCn )
 

Faster than using ADOX
Works with all RDBMSs even where ADOX is not supported or not fully supported.
Same syntax works for different RDBMSs, thereby enabling portable programming accross different RDBMSs
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10207
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby Compuin » Sat Apr 01, 2017 12:36 pm

Thanks

In order to work with Ado with MSSQL...should I install some specific driver?
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Ejemplo de Tdatarow para crear Base de datos y tablas

Postby nageswaragunupudi » Sat Apr 01, 2017 3:12 pm

Not necessary
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10207
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin para Harbour/xHarbour

Who is online

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