wowsoso / go-dbf Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/go-dbf
Automatically exported from code.google.com/p/go-dbf
What steps will reproduce the problem?
1. have a DBF file with numeric fields with length 7, decimal places 2.
2. try to create RDBMS tables from table info
3. mismatch (we have only info about field length).
Please provide any additional information below.
gthomas@waterhouse:~/src/code.google.com/p/go-dbf$ hg diff -r 7 -w
diff -r 2d1196663b9d godbf/dbfreader.go
--- a/godbf/dbfreader.go Wed Apr 23 09:41:47 2014 +1000
+++ b/godbf/dbfreader.go Sat Jul 05 08:51:13 2014 +0200
@@ -1,13 +1,14 @@
package godbf
import (
+ "errors"
"fmt"
- "errors"
"os"
+ "strconv"
+ "strings"
"time"
+
"code.google.com/p/mahonia"
- "strings"
- "strconv"
)
type DbfTable struct {
@@ -52,6 +53,7 @@
fieldName string
fieldType string
fieldLength uint8
+ fieldDecPlaces uint8
fieldStore [32]byte
}
@@ -102,7 +104,7 @@
case 'C':
err = dt.AddTextField(fieldName, s[offset+16])
case 'N':
- err = dt.AddNumberField(fieldName, s[offset+16])
+ err = dt.AddNumberField(fieldName, s[offset+16],
s[offset+17])
case 'F':
err = dt.AddFloatField(fieldName, s[offset+16])
case 'L':
@@ -317,7 +319,6 @@
value = strings.TrimSpace(s)
-
//fmt.Printf("raw value:[%#v]\n", dt.dataStore[(offset + recordOffset):((offset + recordOffset) + int(dt.Fields[fieldIndex].fieldLength))])
//fmt.Printf("utf-8 value:[%#v]\n", []byte(s))
//value = string(dt.dataStore[(offset + recordOffset):((offset + recordOffset) + int(dt.Fields[fieldIndex].fieldLength))])
@@ -379,23 +380,23 @@
}
func (dt *DbfTable) AddTextField(fieldName string, length uint8) (err error) {
- return dt.addField(fieldName, 'C', length)
+ return dt.addField(fieldName, 'C', length, 0)
}
-func (dt *DbfTable) AddNumberField(fieldName string, length uint8) (err error)
{
- return dt.addField(fieldName, 'N', length)
+func (dt *DbfTable) AddNumberField(fieldName string, length, decPlaces uint8)
(err error) {
+ return dt.addField(fieldName, 'N', length, decPlaces)
}
func (dt *DbfTable) AddFloatField(fieldName string, length uint8) (err error) {
- return dt.addField(fieldName, 'F', length)
+ return dt.addField(fieldName, 'F', length, 0)
}
func (dt *DbfTable) AddBooleanField(fieldName string) (err error) {
- return dt.addField(fieldName, 'L', 1)
+ return dt.addField(fieldName, 'L', 1, 0)
}
func (dt *DbfTable) AddDateField(fieldName string) (err error) {
- return dt.addField(fieldName, 'D', 8)
+ return dt.addField(fieldName, 'D', 8, 0)
}
// NumberOfRecords return number of rows in dbase table
@@ -423,7 +424,12 @@
return df.fieldLength
}
-func (dt *DbfTable) addField(fieldName string, fieldType byte, length uint8)
(err error) {
+// FieldDecPlaces returns fieldDecPlaces
+func (df *DbfField) FieldDecPlaces() uint8 {
+ return df.fieldDecPlaces
+}
+
+func (dt *DbfTable) addField(fieldName string, fieldType byte, length,
decPlaces uint8) (err error) {
if dt.dataEntryStarted {
return errors.New("Once you start entering data to the dbase table or open an existing dbase file, altering dbase table schema is not allowed!")
@@ -439,6 +445,10 @@
df.fieldName = s
df.fieldType = string(fieldType)
df.fieldLength = length
+ df.fieldDecPlaces = 0
+ if fieldType == 'N' {
+ df.fieldDecPlaces = decPlaces
+ }
slice := dt.convertToByteSlice(s, 10)
@@ -463,6 +473,9 @@
// length of field
df.fieldStore[16] = length
+ // number of decimal places
+ df.fieldStore[17] = df.fieldDecPlaces
+
//fmt.Printf("addField | append:%v", df)
dt.fields = append(dt.fields, *df)
Original issue reported on code.google.com by [email protected]
on 5 Jul 2014 at 6:52
I am wanting to use go-dbf to parse a dbf file on the web without saving it on
to the machine. I have looked through the source code and I think this would be
possible with some refactoring. I could go ahead and propose something, but I
haven't worked with mercurial before so don't know how contributing works.
Original issue reported on code.google.com by [email protected]
on 30 Jul 2014 at 12:13
Mahonia maintainers have decided to discontinue support, and suggest
go.text/encoding to achieve the same ends.
https://code.google.com/p/mahonia/
code.google.com go.text/encoding/
An example of a cutover:
https://github.com/oov/the_platinum_searcher/commit/c5c5960fb6e327048d8ffc5967b7
0a17fdf2043f
A brief look at go.text/encoding indicates it's a very different approach. This
is a nice-to-have, but not yet critical unless a manhonia bug appears that
effects go-dbf.
Original issue reported on code.google.com by lycanthropic.dreaming
on 23 Apr 2014 at 12:06
$ go get code.google.com/p/go-dbf/godbf
package code.google.com/p/go-dbf/godbf
imports mahonia: unrecognized import path "mahonia"
Original issue reported on code.google.com by [email protected]
on 29 Mar 2014 at 12:49
added absolute URL for mahonia package
Original issue reported on code.google.com by ianmac45
on 14 Apr 2014 at 5:06
Attachments:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.