Skip to content

Instantly share code, notes, and snippets.

@JodiTheTigger
Last active December 16, 2015 18:49
Show Gist options
  • Save JodiTheTigger/5480338 to your computer and use it in GitHub Desktop.
Save JodiTheTigger/5480338 to your computer and use it in GitHub Desktop.
sqlTablesToCsClasses.py converts the result of a table creation sql text dump, into sqlite-net CSharp classes.
#!/usr/bin/python2
"""
sqlTablesToCsClasses.py Turns sql table creation text dumps into sqlite-net CSharp classes.
Copyright (C) 2013 Richard Maxwell <jodi.the.tigger@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
with open(sys.argv[1]) as f:
content = f.readlines()
print "using System;"
print ""
inTable=False
for line in content:
if (inTable is False):
if (line.startswith("create table")):
print "public class ", line.split()[2]
print "{"
inTable=True
else:
if (line.startswith(");")):
print "};"
print ""
inTable=False
else:
splits = line.split()
if (len(splits) > 1) and (splits[0].startswith("-") is False):
dataType="int"
dataTypeName=splits[1]
dataName=splits[0]
if (dataTypeName=="text"):
dataType="string"
if (dataTypeName=="date"):
dataType="DateTime"
if (dataTypeName=="double"):
dataType="double"
print " public ", dataType, " ", dataName, " { get; set; }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment