Changing a db

jda jda at his.com
Fri Jul 22 15:36:17 CDT 2005


Hi Ruslan,

A few questions here.

I need to change the length of a string field when updating a 
database (API way). I want the length to go from 10 to 24.

To do this, I try to open the old (original) db and get an exception 
(schema doesn't match). Fine.

I then open the db as a VDatabase and try

   vdb.Table("format").StringField("sepLastNamesWith").MaxLength = 24

This works, BUT all the records after the first record had their data deleted!

That's the first problem.

Then I found I COULD do this the SQL way and it worked, preserving 
all data. I used this:

call vdb.SQLExecute("ALTER TABLE format CHANGE sepLastNamesWith 
sepLastNamesWith String (24)")

But then when the db was opened again the API way I got an error:

  Schema does not match (field sepLastNamesWith -- wrong NULLABLE status).

So now I'm doing this, which works:

if vdb.Table("format").StringField("sepLastNamesWith").MaxLength < 24 then
        call vdb.SQLExecute("ALTER TABLE format CHANGE 
sepLastNamesWith sepLastNamesWith String (24)")
         vdb.Table("format").StringField("sepLastNamesWith").IsNullable = false
  end if

As you can see, I'm mixing API and SQL commands. But it works! In 
V1.x you told us not to do this. Will it cause problems in V2?

Thanks,

Jon


More information about the Valentina-beta mailing list