!#/usr/bin/env python3.6

import pypyodbc
import re
import sqlite3

output_db = ""

fp = re.compile('[-+]?[0-9]*\.?[0-9]+')

def isfloat(str):

    if fp.match(str) != None:
        return True

    return False

conn = pypyodbc.connect("")
cur = conn.cursor()

output_conn = sqlite3.connect(output_db)
output_cur = conn.cursor()

cur.execute("select * from sys.tables")

tables = []

for row in cur.fetchall():
    tables.append(row[0])

for table in tables:
    print(table)

    cur.execute("select * from {}".format(table))

    column_names = []

    for d in cur.description:
        column_names.append(d[0])

    x = 0

    for row in cur.fetchall():
        table_data.append(row)
        x = x + 1

    max_len = 0

    num_fields = len(column_names)

    is_digit = [True] * num_fields
    is_float = [True] * num_fields
    is_string = [False] * num_fields

    for datum in table_data:

        y = 0

        for entry in datum:

            try:
                if len(entry) != 0:
                    is_digit[y] = is_digit[y] and entry.isdigit()
                    is_float[y] = is_float[y] and isfloat(entry)
            except:
                print(entry)

            y = y + 1

    for x in range(num_fields):
        if is_digit[x] and is_float[x]:
            is_float[x] = False
        if not (is_digit[x] or is_float[x]):
            is_string[x] = True

    query = "create table if not exists {} (".format(table)

    x = 0

    for col in column_names:

        if (col[0]).isdigit():
            col = "_" + col

        query = query + col

        if is_digit[x]:
            query = query + " integer, "
        elif is_float[x]:
            query = query + " real, "
        else:
            query = query + " text, "

        x = x + 1

    query = query[:-2]

    query = query + ")"


    try:
        output_cur.execute(query)
    except:
        print(query)

    output_conn.commit()

    x = 0

    insert_query = "insert into {} values (".format(table) + \
      ("?," * num_fields)

    # Remove trailing ',' and add ')'
    insert_query = insert_query[:-1]
    insert_query = insert_query + ")"

    output_cur.executemany(insert_query, table_data)

    output_conn.commit()

output_conn.close()

@@ -1,29 +1,13 @@
-!#/usr/bin/env python3.6%0A
+import os
 %0Aimp
@@ -58,16 +58,19 @@
 t_db = %22
+.db
 %22%0A%0Afp = 
@@ -81,16 +81,17 @@
 ompile('
+%5E
 %5B-+%5D?%5B0-
@@ -102,16 +102,17 @@
 .?%5B0-9%5D+
+$
 ')%0A%0Adef 
@@ -195,16 +195,89 @@
  False%0A%0A
+try:%0A    os.remove(output_db)%0Aexcept:%0A    print(%22Could not delete db.%22)%0A%0A
 conn = p
@@ -367,24 +367,31 @@
 utput_cur = 
+output_
 conn.cursor(
@@ -501,16 +501,87 @@
 ow%5B0%5D)%0A%0A
+tables = %5B'owners', 'canals', 'orders', 'crops', 'ordersdetailcrops'%5D%0A%0A
 for tabl
@@ -597,26 +597,8 @@
 es:%0A
-    print(table)%0A%0A
     
@@ -736,117 +736,8 @@
 %5D)%0A%0A
-    x = 0%0A%0A    for row in cur.fetchall():%0A        table_data.append(row)%0A        x = x + 1%0A%0A    max_len = 0%0A%0A
     
@@ -884,99 +884,234 @@
     
-for datum in table_data:%0A%0A        y = 0%0A%0A        for entry in datum:%0A%0A            try:%0A    
+x = 0%0A%0A    table_data = %5B%5D%0A%0A    for row in cur.fetchall():%0A        temp_row = %5B%5D%0A%0A        y = 0%0A%0A        for entry in row:%0A            str_entry = str(entry)%0A            if str_entry == 'None':%0A                str_entry = ''%0A%0A
     
@@ -1125,16 +1125,20 @@
  if len(
+str_
 entry) !
@@ -1142,20 +1142,16 @@
 ) != 0:%0A
-    
         
@@ -1188,16 +1188,20 @@
 %5By%5D and 
+str_
 entry.is
@@ -1208,20 +1208,16 @@
 digit()%0A
-    
         
@@ -1262,23 +1262,28 @@
 isfloat(
+str_
 entry)%0A
+%0A
         
@@ -1290,43 +1290,93 @@
     
-except:%0A                print(entry
+temp_row.append(str_entry)%0A%0A            y = y + 1%0A%0A        table_data.append(temp_row
 )%0A%0A 
@@ -1378,33 +1378,29 @@
 w)%0A%0A        
-    y = y
+x = x
  + 1%0A%0A    fo
@@ -2335,16 +2335,66 @@
  + %22)%22%0A%0A
+    for datum in table_data:%0A        try:%0A        
     outp
@@ -2411,12 +2411,8 @@
 cute
-many
 (ins
@@ -2422,26 +2422,62 @@
 _query, 
-table_data
+datum)%0A        except:%0A            print(query
 )%0A%0A    o

Fix to regular expression. Work on None checking.