Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
azwalzaman opened this issue Aug 20, 2024 · 3 comments

Comments

@azwalzaman
Copy link

azwalzaman commented Aug 20, 2024

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
}

@alexbrainman
Copy link
Owner

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

@azwalzaman
Copy link
Author

azwalzaman commented Aug 22, 2024

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

@alexbrainman
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants