Skip to content
Permalink
Browse files

add numpy types to class Database

  • Loading branch information...
sdpython committed Apr 20, 2014
1 parent 5720968 commit f4ad76a97d17303bc7e711828e949234ad69ed52
Showing with 17 additions and 12 deletions.
  1. +1 −0 src/pyensae/__init__.py
  2. +16 −12 src/pyensae/sql/database_core.py
@@ -17,3 +17,4 @@ def check( log = False):
from .sql.database_helper import import_flatfile_into_database
from .file.file_helper import replace_comma_by_point
from .finance.astock import StockPrices
from .sql.database_main import Database
@@ -5,7 +5,7 @@
@brief @see cl Database
"""

import os, sys, math, re, time, decimal, sqlite3 as SQLite, datetime
import os, sys, math, re, time, decimal, sqlite3 as SQLite, datetime, numpy

module_odbc = None

@@ -845,23 +845,27 @@ def create_table (self, table, columns, temporary = False) :
if isinstance (val [1], tuple) : v,l = val [1]
else : v,l = val [1], 2048

if l > 8000 : col.append (val [0] + " TEXT")
elif v is str : col.append (val [0] + " VARCHAR(%d)" % l)
elif v is int : col.append (val [0] + " INTEGER")
elif v is float : col.append (val [0] + " FLOAT")
elif v is decimal.Decimal : col.append (val [0] + " Decimal")
elif v is datetime.datetime : col.append (val [0] + " DATETIME")
if l > 8000 : col.append (val [0] + " TEXT")
elif v is str : col.append (val [0] + " VARCHAR(%d)" % l)
elif v is int : col.append (val [0] + " INTEGER")
elif v is float : col.append (val [0] + " FLOAT")
elif v is numpy.int64 : col.append (val [0] + " INTEGER")
elif v is numpy.float64 : col.append (val [0] + " FLOAT")
elif v is decimal.Decimal : col.append (val [0] + " Decimal")
elif v is datetime.datetime : col.append (val [0] + " DATETIME")
else :
raise DBException ("unable to add column " + str (c) + " ... " + str (val) + " v= " + str (v))
else :
if isinstance (val [1], tuple) : v,l = val [1]
else : v,l = val [1], 2048

if v is str : col.append (val [0] + " TEXT")
elif v is int : col.append (val [0] + " INTEGER")
elif v is float : col.append (val [0] + " FLOAT")
elif v is decimal.Decimal : col.append (val [0] + " Decimal")
elif v is datetime.datetime : col.append (val [0] + " DATETIME")
if v is str : col.append (val [0] + " TEXT")
elif v is int : col.append (val [0] + " INTEGER")
elif v is float : col.append (val [0] + " FLOAT")
elif v is numpy.int64 : col.append (val [0] + " INTEGER")
elif v is numpy.float64 : col.append (val [0] + " FLOAT")
elif v is decimal.Decimal : col.append (val [0] + " Decimal")
elif v is datetime.datetime : col.append (val [0] + " DATETIME")
else :
raise DBException ("unable to add column " + str (c) + " ... " + str (val) + " v= " + str (v))

0 comments on commit f4ad76a

Please sign in to comment.
You can’t perform that action at this time.