Board index » delphi » ALTER TABLE makes VARCHAR column too long

ALTER TABLE makes VARCHAR column too long

I have a PREMISES table with a field ADDRESS1 VARCHAR(30), that I want to
expand to VARCHAR(50).

I execute the command ALTER TABLE PREMISES ALTER ADDRESS1 VARCHAR(50). When
I check out the table ADDRESS1 is defined as VARCHAR(52).  Is this a known
bug and if so is there a workaround?

I have tried restoring from a backup but this doesn't cure the problem.

 

Re:ALTER TABLE makes VARCHAR column too long


Quote
"Richard Nagle" <rna...@tickets.com> wrote in message

news:3ab63123_1@dnews...

Quote
> Sorry that was just a typo. I've identified the problem as being in
> IBWorkbench so I'll ask the question in the IBWorkbench group.

The problem has been reproduced and will be fixed in the upcoming version.

--
Martijn Tonies
Upscene Productions
http://www.upscene.com

InterBase Workbench - the developer tool for InterBase
http://www.interbaseworkbench.com

Re:ALTER TABLE makes VARCHAR column too long


Sorry for earlier confusions I have been testing this further and think it
is a bug in Interbase (I have tested it against both OpenSource IB and
Firebird 0.9.4, using IBConsole and IBWorkbench and it occurs in all
combinations).

Try this:

CREATE TABLE TEST_ALT(
  REF INTEGER NOT NULL PRIMARY KEY,
  TXT1 VARCHAR(3),
  TXT2 VARCHAR(3))

ALTER TABLE TEST_ALT
  ALTER TXT1 TYPE VARCHAR(5)

INSERT INTO TEST_ALT
  VALUES(1,'1234567','123')

SELECT * FROM TEST_ALT

On my system the value '1234567' is stored in TXT1 of the new record, how
can this be TXT1 should be defined as VARCHAR(5) and should reject the value
'1234567' as being too large?

Further, if look at the definition of the field in RDB$FIELDS the
RDB$FIELD_LENGTH has a value of 7 while the RDB$CHARACTER_LENGTH has a value
of 5.

Can others replicate this problem ?

Richard Nagle
rna...@tickets.com
http://www.tickets.com

Re:ALTER TABLE makes VARCHAR column too long


"Craig Stuntz (TeamB)" <cstuntz@no_spam.vertexsoftware.com> wrote in message

Quote
> Richard Nagle wrote:
> > On my system the value '1234567' is stored in TXT1 of the new record,
how
> > can this be TXT1 should be defined as VARCHAR(5) and should reject the
value
> > '1234567' as being too large?

> I agree that this should be rejected.

> > Further, if look at the definition of the field in RDB$FIELDS the
> > RDB$FIELD_LENGTH has a value of 7 while the RDB$CHARACTER_LENGTH has a
value
> > of 5.

> This may be correct as VARCHARs have an extra two bytes to store the
> length.  But I do see it's different for TXT2.

This happens only after an ALTER statement... I noticed it too - it was
reported some time ago to me... After that, I noticed the
RDB$CHARACTER_LENGTH field -- figured out that this field was reporting the
true length, until Richard told me he could actually INSERT a longer
string...

Quote
> I'm passing your message along...

Alright...

--
Martijn Tonies
Upscene Productions
http://www.upscene.com

InterBase Workbench - the developer tool for InterBase
http://www.interbaseworkbench.com

Re:ALTER TABLE makes VARCHAR column too long


Quote
Richard Nagle wrote:

> On my system the value '1234567' is stored in TXT1 of the new record, how
> can this be TXT1 should be defined as VARCHAR(5) and should reject the value
> '1234567' as being too large?

        I agree that this should be rejected.

Quote
> Further, if look at the definition of the field in RDB$FIELDS the
> RDB$FIELD_LENGTH has a value of 7 while the RDB$CHARACTER_LENGTH has a value
> of 5.

        This may be correct as VARCHARs have an extra two bytes to store the
length.  But I do see it's different for TXT2.

        I'm passing your message along...

        -Craig

--
Craig Stuntz (TeamB)       Senior Developer, Vertex Systems Corp.
Delphi/InterBase weblog:   http://delphi.weblogs.com
Use Borland servers; posts via others are not seen by TeamB.
For more info, see http://www.borland.com/newsgroups/genl_faqs.html

Re:ALTER TABLE makes VARCHAR column too long


Sorry that was just a typo. I've identified the problem as being in
IBWorkbench so I'll ask the question in the IBWorkbench group.

Thanks anyway.

Craig Stuntz (TeamB) <cstuntz@no_spam.vertexsoftware.com> wrote in message
news:3AB62B4C.B00F5A8B@no_spam.vertexsoftware.com...

Quote

> Richard Nagle wrote:

> > I have a PREMISES table with a field ADDRESS1 VARCHAR(30), that I want
to
> > expand to VARCHAR(50).

> > I execute the command ALTER TABLE PREMISES ALTER ADDRESS1 VARCHAR(50).
When
> > I check out the table ADDRESS1 is defined as VARCHAR(52).  Is this a
known
> > bug and if so is there a workaround?

> First, this syntax doesn't work.  I'm not nitpicking, here; I'm trying
> to reproduce your problem.  I can do:

> ALTER TABLE PREMISES ALTER ADDRESS1 TYPE VARCHAR(50);

> (Note the addition of "TYPE")

> ...but when I do this it works properly.

> -Craig

> --
> Craig Stuntz (TeamB)       Senior Developer, Vertex Systems Corp.
> Delphi/InterBase weblog:   http://delphi.weblogs.com
> Use Borland servers; posts via others are not seen by TeamB.
> For more info, see http://www.borland.com/newsgroups/genl_faqs.html

Re:ALTER TABLE makes VARCHAR column too long


Quote
Richard Nagle wrote:

> I have a PREMISES table with a field ADDRESS1 VARCHAR(30), that I want to
> expand to VARCHAR(50).

> I execute the command ALTER TABLE PREMISES ALTER ADDRESS1 VARCHAR(50). When
> I check out the table ADDRESS1 is defined as VARCHAR(52).  Is this a known
> bug and if so is there a workaround?

        First, this syntax doesn't work.  I'm not nitpicking, here; I'm trying
to reproduce your problem.  I can do:

ALTER TABLE PREMISES ALTER ADDRESS1 TYPE VARCHAR(50);

        (Note the addition of "TYPE")

        ...but when I do this it works properly.

        -Craig

--
Craig Stuntz (TeamB)       Senior Developer, Vertex Systems Corp.
Delphi/InterBase weblog:   http://delphi.weblogs.com
Use Borland servers; posts via others are not seen by TeamB.
For more info, see http://www.borland.com/newsgroups/genl_faqs.html

Other Threads