Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 10 total
Thread Cannot add column to existing table
Wed, Feb 21 2007 9:59 AMPermanent Link

Bob Murdoch
Using DBIsam v3.10:
I am creating an in-memory table in code, and later trying to add a column to that table.  I get the error 'Cannot perform this operation on an open dataset'.

Here is the code used to create the table:

  FTable := TDBIsamTable.create(self);
  with FTable do begin
     DatabaseName := 'Memory';
     TableName := 'Temp';
     if not Exists then begin
        with FieldDefs do begin
           clear;
           with AddFieldDef do begin
              Name := 'TABLE_NAME';
              DataType := ftString;
              Required := True;
              Size := 50;
           end;
        end;
        with IndexDefs do begin
           clear;
           with AddIndexDef do begin
             Name := '';
             Fields := 'TABLE_NAME';
             Options := [ixPrimary];
           end;
        end;
        CreateTable;
     end;
     Open;
  end;

And here is the code that blows up on ExecSql:

  FTable.close;
  with TDBIsamQuery.create(NIL) do try
     DatabaseName := 'Memory';
     with sql do begin
        add('alter table temp');
        add('   add column ' + vColumnName + ' integer;');
     end;
     ExecSql;
  finally
     free;
     FTable.Open;
  end;

In the code, vColumnName would look like "RestoreLog_20070101'.

Thanks for your help

Bob M..
Wed, Feb 21 2007 11:05 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Bob

There must be another table component pointing to the in-memory table somewhere.


Roy Lambert
Wed, Feb 21 2007 11:14 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Bob,

<< Using DBIsam v3.10:

I am creating an in-memory table in code, and later trying to add a column
to that table.  I get the error 'Cannot perform this operation on an open
dataset'. >>

Are you sure that the ExecSQL line is producing the error ?  The query is
created new every time, so there really is no way for it to be opened when
the ExecSQL line is executed.

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Feb 21 2007 12:57 PMPermanent Link

Bob Murdoch
Roy Lambert <roy.lambert@skynet.co.uk> wrote:

>> There must be another table component pointing to the in-memory table somewhere.

I just tried changing the table name to something nonsensical so that it couldn't possibly be used anywhere else.  I also commented out the .Open when creating the table, and still get the same error when
trying the sql to create the additional column.


Bob M..

Wed, Feb 21 2007 12:58 PMPermanent Link

Bob Murdoch
"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote:

>>
Are you sure that the ExecSQL line is producing the error ?  The query is
created new every time, so there really is no way for it to be opened when
the ExecSQL line is executed.
<<

Absolutely..
Wed, Feb 21 2007 1:21 PMPermanent Link

Bob Murdoch
Bob Murdoch <bm@dashlogistics.com> wrote:

>> Absolutely..

Seems that was a mis-statement.  There was a Try/Finally that included a call to FTable.DeleteTable that was causing the error message.

The true error message is "Error 11010: Table Parselog.dat does not exist".  Here is the code - it's basically the same as the first time:

  with FTable do begin
     DatabaseName := 'Memory';
     TableName := 'ParseLog';
     if not Exists then begin
        with FieldDefs do begin
           clear;
           with AddFieldDef do begin
              Name := 'TABLE_NAME';
              DataType := ftString;
              Required := True;
              Size := 50;
           end;
        end;
        with IndexDefs do begin
           clear;
           with AddIndexDef do begin
             Name := '';
             Fields := 'TABLE_NAME';
             Options := [ixPrimary];
           end;
        end;
        CreateTable;
     end;
     Open;
  end;

  with TdbIsamQuery.create(NIL) do try
     DatabaseName := 'Memory';
     with sql do begin
        add('alter table Parselog');
        add('   add column ' + vColumnName + ' integer;');
     end;
     ExecSql;
  finally
     free;
  end;

Thu, Feb 22 2007 6:45 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Bob,

<< The true error message is "Error 11010: Table Parselog.dat does not
exist".  Here is the code - it's basically the same as the first time: >>

Are both the FTable component and the dynamic query using the same session
(SessioName property) ?

--
Tim Young
Elevate Software
www.elevatesoft.com

Thu, Feb 22 2007 9:44 PMPermanent Link

Bob Murdoch
"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote:

>>
Are both the FTable component and the dynamic query using the same session
(SessioName property) ?
<<

I did not set the session name for the table or the query, with the assumption that they would use the default session.  This is not a multi-threaded app.

I did try to use a session component just now, and assigned the component name to both, with the same problem.  I also tried changing the table name to 'ParseLog.dat',
just in case the extension was required (even though this is an inmemory table).  Still same problem though.

thank you,

Bob M..
Fri, Feb 23 2007 3:36 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Bob


Any chance you can post me a demo to check things out? If so I'll have a look at it this weekend.

Roy Lambert
Fri, Feb 23 2007 7:37 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Bob,

<< I did not set the session name for the table or the query, with the
assumption that they would use the default session.  This is not a
multi-threaded app.

I did try to use a session component just now, and assigned the component
name to both, with the same problem.  I also tried changing the table name
to 'ParseLog.dat', just in case the extension was required (even though this
is an inmemory table).  Still same problem though. >>

Well, the only way that an in-memory table would not be found is if it isn't
actually there.  If you could send me something that reproduces the issue, I
will gladly take a look and tell you what's going on.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image