Skip to content
This repository has been archived by the owner on Jun 4, 2020. It is now read-only.

Commit

Permalink
fix character trucation
Browse files Browse the repository at this point in the history
fix #55
  • Loading branch information
vmora committed Apr 7, 2017
1 parent 2e02fc5 commit 59ca6ca
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,17 +938,24 @@ def commit(sqlite_filename, commit_msg, pg_conn_info,commit_pg_user = ''):
[brch+'_rev_begin', brch+'_rev_end',
brch+'_parent', brch+'_child']
for brch in other_branches], [])
pcur.execute("SELECT column_name, data_type "
"FROM information_schema.columns "
"WHERE table_schema = '"+table_schema+"' "
"AND table_name = '"+table+"'")
pcur.execute("""
SELECT column_name, data_type, character_maximum_length
FROM information_schema.columns
WHERE table_schema = '{table_schema}'
AND table_name = '{table}'
""".format(table_schema=table_schema, table=table))
cols = ""
cols_cast = ""
for col in pcur.fetchall():
if col[0] not in other_branches_columns:
cols += quote_ident(col[0])+", "
if col[1] != 'ARRAY':
cast = "::"+col[1] if col[1] != 'USER-DEFINED' else ""
if col[1] == 'USER-DEFINED':
cast = ""
elif col[1] == 'character' and col[2]:
cast = "::varchar"
else:
cast = "::"+col[1]
cols_cast += quote_ident(col[0])+cast+", "
else :
cols_cast += ("regexp_replace(regexp_replace("
Expand Down Expand Up @@ -1010,12 +1017,14 @@ def historize( pg_conn_info, schema ):
raise RuntimeError("no schema specified")
pcur = Db(psycopg2.connect(pg_conn_info))

pcur.execute("CREATE TABLE "+schema+".revisions ("
"rev serial PRIMARY KEY, "
"commit_msg varchar, "
"branch varchar DEFAULT 'trunk', "
"date timestamp DEFAULT current_timestamp, "
"author varchar)")
pcur.execute("""
CREATE TABLE {schema}.revisions (
rev serial PRIMARY KEY,
commit_msg varchar,
branch varchar DEFAULT 'trunk',
date timestamp DEFAULT current_timestamp,
author varchar)
""".format(schema=schema))
pcur.commit()
pcur.close()
add_branch( pg_conn_info, schema, 'trunk', 'initial commit' )
Expand Down

0 comments on commit 59ca6ca

Please sign in to comment.