Giter Club home page Giter Club logo

go-dbf's Introduction

go-dbf's People

Contributors

aydink avatar

Watchers

 avatar

go-dbf's Issues

Retire mahonia for code.google.com/p/go.text/encoding

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 failed

$ 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

Add ability to create dbf table from byte array

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

Add decimal places support to DbfField

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.