sqlite3 create table col width?

jim-on-linux inq1ltd at inqvista.com
Sat Aug 4 15:36:07 EDT 2007


On Saturday 04 August 2007 14:05, Carsten Haese 
wrote:
> On Sat, 2007-08-04 at 13:51 -0400, jim-on-linux 
wrote:
> > PY help,
> >
> > Using sqlite3 v3.1.3
> >
> > When I create a table collumn using;
> >
> > newcollum VARCHAR(35),
> >
> > I get a default of 10 spaces.
> >
> > No matter what I set the size to I get 10
> > spqces, even using varchar(0) defaults to 10
> > spaces.
> >
> > I would appreciae the help if someone could
> > tell me what I'm missing, I want to varry the
> > column sizes.
>
> What you're missing is that sqlite columns are
> type-less. Column type
>
> and size are irrelevant:
> >>> import sqlite3
> >>> conn = sqlite3.connect(":memory")
> >>> cur = conn.cursor()
> >>> cur.execute("create table t1 (c1
> >>> varchar(35))")
>
> <sqlite3.Cursor object at 0xb7f6dbf0>
>
> >>> cur.executemany("insert into t1(c1)
> >>> values(?)",
>
> ...     [ ("X"*i*10,) for i in range(10) ] )
>
> >>> cur.execute("select * from t1")
>
> <sqlite3.Cursor object at 0xb7f6dbf0>
>
> >>> for row in cur: print row
>
> ...
> (u'',)
> (u'XXXXXXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>XXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>XXXXXXXXXXXXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>XXXXXXXXXXXXXXXXXXXXXXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',)
> (u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
>)
>
> Even though the column was created to be 35
> characters wide, it'll happily accept
> 100-character strings.
>
> HTH,
>
> --
> Carsten Haese
> http://informixdb.sourceforge.net


Right, the data is there. 
My question is framed wrong.  Your answer pointed 
out the flaw in the question.

Since I'm on linux, the database can be opened 
with Knoda.  Once opened the table collumns are 
always 10 spaces so all the data is not readable 
as presented.  Not quite a python problem.  

I can Tk a display for the data, just thought I 
could save time by letting the user open the 
table and read the data right from the table.

Thanks for the help.

jim-on-linux

 























More information about the Python-list mailing list