-
Notifications
You must be signed in to change notification settings - Fork 12
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
Problem Finding Field in created table #145
Comments
Hi Com1Software, Thank you for reporting this issue. I’ll take a closer look into the problem. Meanwhile, could you verify if this issue persists with the latest version of the package? It would also be helpful if you could provide a minimal reproducible example showing how the new table is created and the FieldByName operation is used. Best regards, |
@Com1Software I cannot reproduce the problem. Where in your code does it fail? If I see correctly, all occurrences of Alternatively, it would be helpful if you could activate the debug mode and provide me with the output: |
Hi Valentin,
Thanks for looking into this.
Below is a minimal program to show the problem.
When you compile and run the program the first time it will create a tag dbf
When you run it a second time it tries to find the tag and testing fields -
this is where I am seeing the error out because it cannot find the tag.
Thanks again Dave
package main
import (
"fmt"
"os"
"github.com/Valentin-Kaiser/go-dbase/dbase"
"golang.org/x/text/encoding/charmap"
)
type Tags struct {
Tag string `dbase:"TAG"`
Testing string `dbase:"TESTING"`
}
func main() {
tt := "TAGS.DBF"
if _, err := os.Stat(tt); err == nil {
table, err := dbase.OpenTable(&dbase.Config{
Filename: "TAGS.DBF",
TrimSpaces: true,
WriteLock: true,
})
if err != nil {
panic(err)
}
defer table.Close()
row, err := table.Row()
if err != nil {
panic(err)
}
p := Tags{
Testing: "test123",
}
row, err = table.RowFromStruct(p)
if err != nil {
panic(err)
}
fmt.Println(row)
err = row.FieldByName("TAG").SetValue("TAG_VALUE")
if err != nil {
panic(err)
}
err = row.FieldByName("TESTING").SetValue("TEST_VALUE")
if err != nil {
panic(err)
}
err = row.Write()
if err != nil {
panic(err)
}
fmt.Printf(
"Last modified: %v Columns count: %v Record count: %v File size: %v \n",
table.Header().Modified(0),
table.Header().ColumnsCount(),
table.Header().RecordsCount(),
table.Header().FileSize(),
)
} else {
file, err := dbase.NewTable(
dbase.FoxProVar,
&dbase.Config{
Filename: tt,
Converter: dbase.NewDefaultConverter(charmap.Windows1250),
TrimSpaces: true,
},
tcolumns(),
64,
nil,
)
if err != nil {
panic(err)
}
defer file.Close()
row, err := file.RowFromStruct(&Tags{
Tag: "TAG",
})
if err != nil {
panic(err)
}
err = row.Add()
if err != nil {
panic(err)
}
fmt.Printf(
"Last modified: %v Columns count: %v Record count: %v File size: %v \n",
file.Header().Modified(0),
file.Header().ColumnsCount(),
file.Header().RecordsCount(),
file.Header().FileSize(),
)
}
}
func tcolumns() []*dbase.Column {
tagCol, err := dbase.NewColumn("Tag", dbase.Varchar, 80, 0, false)
testCol, err := dbase.NewColumn("Testing", dbase.Character, 80, 0, true)
if err != nil {
panic(err)
}
return []*dbase.Column{
tagCol,
testCol,
}
}
…On Sun, Dec 8, 2024 at 6:22 PM Valentin Kaiser ***@***.***> wrote:
@Com1Software <https://github.com/Com1Software> I cannot reproduce the
problem. Where in your code does it fail? If I see correctly, all
occurrences of FieldByName are commented out.
Alternatively, it would be helpful if you could activate the debug mode
and provide me with the output: dbase.Debug(true, os.Stdout).
—
Reply to this email directly, view it on GitHub
<#145 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB4POYGID2KLSTRIGIFETA32ETIEBAVCNFSM6AAAAABTHS3H3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRWGQZTQNJVGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Describe the bug
A clear and concise description of what the bug is.
Does not find field in newly created table using
err = row.FieldByName("TAG").SetValue("CHANGED_PRODUCT_NAME")
Link to repo with below code
https://github.com/Com1Software/Video-Web-Server
To Reproduce
Example code to reproduce the behavior:
Expected behavior
To find the field in the created table
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: