odbc icon indicating copy to clipboard operation
odbc copied to clipboard

When Querying Tally ERP Through ODBC Certain Fields Cause A Wrong Column Error

Open azwalzaman opened this issue 1 year ago • 4 comments

So this works perfectly for most queries with Tally but for certain fields I get this error wrong column #0 length 0 returned, 8 expected. Same code works for say SELECT $Name FROM StockItem and the query that causes errors here works fine with PyODBC. Any idea what I can do for this? The value of the field when extracted through PyODBC is a string of the form Price/Unit for example 99.00/nos

import (
	"database/sql"
	"fmt"
	"log"
)

func ReadProducts(db *sql.DB) {
	rows, err := db.Query("SELECT $StandardPrice FROM StockItem")
	if err != nil {
		log.Fatal("Failed to execute query:", err)
	}
	defer rows.Close()

	for rows.Next() {
		var stockItemName sql.NullString

		err := rows.Scan(&stockItemName)
		if err != nil {
			log.Fatal("Failed to scan row:", err)
		}

		fmt.Printf("Stock Item Name: %s\n", stockItemName.String)
	}

	if err = rows.Err(); err != nil {
		log.Fatal("Error occurred during row iteration:", err)
	}
}

Code for the connection

import (
	"database/sql"

	_ "github.com/alexbrainman/odbc"
)

func GetTallyConnection() (*sql.DB, error) {
	connStr := "DSN=TallyODBC64_9000;DRIVER=Tally ODBC DRIVER64;Server=localhost;Port=9000;"

	db, err := sql.Open("odbc", connStr)
	if err != nil {
		return nil, err
	}

	return db, nil
}

azwalzaman avatar Aug 20 '24 02:08 azwalzaman

No idea.

I used this driver to connect to MS SQL Server. Never to TallyODBC64_9000 . Maybe you can adjust the code so it works with TallyODBC64_9000 .

Alex

alexbrainman avatar Aug 22 '24 08:08 alexbrainman

No idea.

I used this driver to connect to MS SQL Server. Never to TallyODBC64_9000 . Maybe you can adjust the code so it works with TallyODBC64_9000 .

Alex

Yeah, fair. I was considering it already actually but I wanted to see if you have any idea of what it could be first. Also I just realized I forgot to change some of the variable names. I was playing around with the fields a bit to see what was causing the issue haha

azwalzaman avatar Aug 22 '24 10:08 azwalzaman

I was considering it already actually but I wanted to see if you have any idea of what it could be first.

No idea. But all source code is there.

Alex

alexbrainman avatar Aug 22 '24 10:08 alexbrainman

@azwalzaman Facing same issue while fetching form Tally, string type fields works fine but number like $OpeningBalance, $ClosingBlance throws runtime error "wrong column #0 length 0 returned, 8 expected". Any luck? Might be $ with number could be issue, just throwing an idea

webmotive1010 avatar Mar 19 '25 15:03 webmotive1010