FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ODBC
Posts: 125
Joined: Wed Oct 19, 2005 02:28 PM
ODBC
Posted: Thu Apr 23, 2009 06:49 PM
Hello to all,

I am trying to create and populate a DBF or MDB via ODBC and have been running into primarykey problems.

Is there any way around this problem with these types of odbc drivers?

Do I need to move to an SQL driver?

here is some of my code:

Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
local adsn
local xdsn
local oodbc
local oodbca

xdsn:="TESTDBF"

oodbc:=TOdbc():new(xdsn)
oOdbc:Create( "Test", { { "Name",  "C", 50, 0,"NOT NULL PRIMARY KEY" },;
                         { "phone", "C", 15, 0,"" },;
                         { "age",   "C",  3, 0,"" } } )

 oodbca:=TdbOdbcDirect():new("SELECT * FROM TEST",oodbc)

           oodbca:AddNew()
           oodbca:Update()

oodbc:end()

return nil



Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: ODBC
Posted: Fri Apr 24, 2009 03:38 AM

Dave,

ADO is the way to go.

Please make a search for ADO in these forums. There are many examples about it :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 125
Joined: Wed Oct 19, 2005 02:28 PM
Re: ODBC
Posted: Mon May 18, 2009 03:40 PM
Antonio,

I have downloaded and installed MS SQL Server 2008

http://www.microsoft.com/express/sql/download/


I created my odbc dsn .

I am able to build my table via odbc very well, however I am having trouble figuring out what is the
best way to populate the table with data.


Any advice would be most appreciated.


Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
local adsn
local xdsn
local oodbc
local oodbca

xdsn:="testsql"

oodbc:=TOdbc():new(xdsn)
oOdbc:Create( "Test", { { "Name",  "C", 50, 0,"NOT NULL PRIMARY KEY" },;
                         { "phone", "C", 15, 0,"" },;
                         { "age",   "C",  3, 0,"" } } )

 oodbca:=TdbOdbcDirect():new("SELECT * FROM TEST",oodbc)

           oodbca:AddNew()
           oodbca:fieldput(1,"tester 123")
           oodbca:Update()

oodbc:end()

return nil


Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
Posts: 125
Joined: Wed Oct 19, 2005 02:28 PM
Re: ODBC
Posted: Mon May 18, 2009 05:06 PM
Got this to work :-)

Looks good now!


Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
local adsn
local xdsn
local oodbc
local oodbca

xdsn:="testsql"

oodbc:=TOdbc():new(xdsn)
oOdbc:Create( "Test", { { "Name",  "C", 50, 0,"NOT NULL PRIMARY KEY" },;
                         { "phone", "C", 15, 0,"" },;
                         { "age",   "C",  3, 0,"" } } )

 oodbca:=TdbOdbcDirect():new("SELECT * FROM TEST",oodbc)

oodbca:open()

           oodbca:AddNew()
           oodbca:fieldput(1,"tester 123")
           oodbca:Update()


Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
Posts: 125
Joined: Wed Oct 19, 2005 02:28 PM
Re: ODBC
Posted: Tue May 19, 2009 12:57 PM
Hello,

I have a new problem.

When I run this code I get

FiveODBC Error TDbOdbcDirect:Update()
[#0] Class:S1000
[Microsoft][SQL Srever Native Client 10.0] Connection is Busy with the Results for another command


Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
local adsn
local xdsn:="testsql"
local oodbc
local odbf
local xt:="TEST"
local x:=0

oodbc:=TOdbc():new(xdsn)
oOdbc:Create( xt, { { "Name",  "C", 50, 0,"NOT NULL PRIMARY KEY" },;
                    { "phone", "C", 15, 0,"" },;
                    { "age",   "C",  3, 0,"" } } )
oodbc:end()
do while x<3
   x=x+1
   oodbc:=TOdbc():new(xdsn)

   odbf:=TdbOdbcDirect():new("SELECT * FROM "+xt ,oodbc)
   odbf:open()
   odbf:AddNew()
   odbf:fieldput(1,"tester"+ltrim(str(x)))
   odbf:Update()
   odbf:complete()

   oodbc:commit()
   oodbc:end()

 enddo
return nil



Any ideas on how to fix this problem?

Thanks
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
Posts: 125
Joined: Wed Oct 19, 2005 02:28 PM
Re: ODBC
Posted: Thu May 21, 2009 12:57 PM
Hello to all:

I got this to work:

using a complete() after each odbf: operation.

Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()
local adsn
local xdsn:="testsql"
local oodbc
local odbf
local xt:="TEST"
local x:=0

oodbc:=TOdbc():new(xdsn)
oOdbc:Create( xt, { { "Name",  "C", 50, 0,"NOT NULL PRIMARY KEY" },;
                    { "phone", "C", 15, 0,"" },;
                    { "age",   "C",  3, 0,"" } } )
oodbc:end()


do while x<10
   x=x+1
   oodbc:=TOdbc():new(xdsn)
   odbf:=TdbOdbcDirect():new("SELECT * FROM "+xt ,oodbc)

   odbf:open()
   odbf:complete()
   odbf:AddNew()
   odbf:complete()
   odbf:fieldput(1,"tester"+ltrim(str(x)))
   odbf:complete()
   odbf:update()
   odbf:complete()
   odbf:end()

   oodbc:commit()
   oodbc:end()
 enddo
return nil
Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: ODBC
Posted: Sun May 24, 2009 05:39 PM

when I run the program I will get the error

SQLDriverConnect error from TODbc:New()

Program:

include "FiveWin.ch"

include "XBrowse.Ch"

include "sql.ch"

function Main()
local adsn
local xdsn
local oodbc
local oodbca

xdsn:=&quot;inkom&quot;

oodbc:=TOdbc():new(xdsn)
oOdbc:Create( &quot;Test&quot;, { { &quot;Name&quot;,  &quot;C&quot;, 50, 0,&quot;NOT NULL PRIMARY KEY&quot; },;
                         { &quot;phone&quot;, &quot;C&quot;, 15, 0,&quot;&quot; },;
                         { &quot;age&quot;,   &quot;C&quot;,  3, 0,&quot;&quot; } } )

 oodbca:=TdbOdbcDirect():new(&quot;SELECT * FROM TEST&quot;,oodbc)
 oodbca:AddNew()
 oodbca:fieldput(1,&quot;tester 123&quot;)
 oodbca:Update()

oodbc:end()

return nil

best regards
kajot

best regards

kajot
Posts: 125
Joined: Wed Oct 19, 2005 02:28 PM
Re: ODBC
Posted: Wed May 27, 2009 12:33 PM
Kajot,


It looks like you are missing oodbca:open() and oodbca:complete() statements in your code.

I added them in and it works.




Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "XBrowse.Ch"
#include "sql.ch"

function Main()
local adsn
local xdsn
local oodbc
local oodbca

xdsn:="testsql"

oodbc:=TOdbc():new(xdsn)
oOdbc:Create( "TEST3", { { "Name", "C", 50, 0,"NOT NULL PRIMARY KEY" },;
{ "phone", "C", 15, 0,"" },;
{ "age", "C", 3, 0,"" } } )

oodbca:=TdbOdbcDirect():new("SELECT * FROM Test3",oodbc)
oodbca:open()
oodbca:complete()
oodbca:AddNew()
oodbca:fieldput(1,"tester 123")
oodbca:complete()
oodbca:Update()
oodbca:complete()
oodbca:end()
oodbc:end()

return nil

Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: ODBC
Posted: Sun May 31, 2009 08:14 AM

I got the same error

SQLDriverConnect error from TODbc:New()

I want to conect to MSSQL 2005 express, ODBC TEST works OK.

bestregards
kajot

best regards

kajot
Posts: 125
Joined: Wed Oct 19, 2005 02:28 PM
Re: ODBC
Posted: Thu Jul 30, 2009 05:24 PM

Antonio,

We have applied an ODBC export that we use within some of our products to create
an sql database table and it works great. As we were testing it the other day I noticed that
I was having an issue that appears to be tied to exceeding 255 fields. We were seeing an index crash
on the temporary dbf file. I put in a field limit of 255 in the ODBC parsing within our product and it
has been working perfectly.

I was wondering if the 255 issue I am is seeing correct.

The product I was working on is using my older version of FWH so I was not sure if that is an issue.

Also I was wondering if there was any way for me to code the temporary files another way to get around the problem.

Last question is if there is a 255 field limit does 64 bits help?

As always for all your help.

Dave Zowasky
Com1 Software, Inc.
http://www.com1software.com
information@com1software.com
330 653-3771

Continue the discussion