Recent

Author Topic: [SOLVED]Frustrating Error "Autoinc Fields are read-only"  (Read 7570 times)

Knipfty

  • Full Member
  • ***
  • Posts: 232
[SOLVED]Frustrating Error "Autoinc Fields are read-only"
« on: July 26, 2012, 02:03:49 am »
Hi All,

A couple of days ago while developing I got some strange error while in the IDE.  Lazarus crashed at the time.  No big deal, I just restarted it.  Since then though I keep getting the following error:

"Autoinc fields are read-only"

I've tracked it down to one particular DBAccess component, a descendant of TTable (I did try a TQuery component as well).  The error occurs when I try to set a master relationship.  It was working before I got that strange error (and no, I don't remember what that was) but since then...

I've tried to delete the components and re-add them.
I've tried creating a datamodule and putting on it new components.  This is where I also tried to set up the TQuery.
I get the same error both in the IDE and when I run the program.

It's as if Lazarus thinks something about the DB now that it shouldn't, but I have no idea where to look.

Any help is greatly appreciated.  I have 3 forms left to build before Saturday when the app will be demo'd for the 1st time.

Thanks in advance

Knipfty
« Last Edit: July 29, 2012, 02:05:22 am by Knipfty »
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

Knipfty

  • Full Member
  • ***
  • Posts: 232
Re: Frustrating Error "Autoinc Fields are read-only"
« Reply #1 on: July 26, 2012, 03:33:19 am »
This is really weird.  I have 3 tables.  The master and 2 slaves.  One slave works fine the other generates the noted error msg above.  I just created 3 new tables that contain only key info pointed the DBTables at them and then updated the master keys accordingly and everything works.  When I point the exact same object back to the original tables, the error comes back.

I've rebuilt Lazarus and that didn't fix anything.

I guess I can recreate the offending tables from scratch, and will tomorrow if nothing else can be found.  The problem is that it doesn't address the problem and can happen again.

If anyone has any ideas,  (even if its "your crazy"), I'd appreciate it.

Thanks again and I'll keep digging,

Knipfty
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Frustrating Error "Autoinc Fields are read-only"
« Reply #2 on: July 26, 2012, 03:59:32 am »
Maybe in one app you have a hardcoded data-filter  and that could make the field read-only?

Or maybe the database engine makes autoincrement fields read-only?

emaza

  • Jr. Member
  • **
  • Posts: 59
    • http://GerenciaDeCondominios.com
Re: Frustrating Error "Autoinc Fields are read-only"
« Reply #3 on: July 26, 2012, 08:11:36 am »
Hi,

Since you asked for crazy ideas, look here:
http://www.lazarus.freepascal.org/index.php/topic,17624.0.html?PHPSESSID=8c26f0e8b57849f9939369ac8488b177

Maybe there is some relation.

avra

  • Hero Member
  • *****
  • Posts: 2584
    • Additional info
Re: Frustrating Error "Autoinc Fields are read-only"
« Reply #4 on: July 26, 2012, 09:44:14 am »
Have you installed some package or patch recently? Do you still have the same problem if you rename "c:\Documents and Settings\yourusername\Application Data\lazarus32" and let Laz recreate it? Maybe bombed IDE has made some weird changes there on exit? Do you backup Laz or at least that dir?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Knipfty

  • Full Member
  • ***
  • Posts: 232
Re: Frustrating Error "Autoinc Fields are read-only"
« Reply #5 on: July 26, 2012, 03:01:29 pm »
Elmug,

The key value being used is an autoinc field in its table and an integer field in the parent table.  And yes, autoinc fields are by their nature readonly and assigned by the DB engine.  Something got corrupted when Laz crashed the other night.

avra,

That is a very god idea.  When I get home this evening, I will rename the that directory and see what happens.  If it's a corruption problem, this should fix it.

emaza,

I glanced at the thread and will read in tis entirity later today when I have some free time.


Thanks all and I'll keep you posted.

If need be, I can always recreate the tables from scratch.
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Frustrating Error "Autoinc Fields are read-only"
« Reply #6 on: July 26, 2012, 11:03:24 pm »
Knipfty,

Check the specs on the database that you are using to see if it complies with the ACID specification, which can make a database that does meet it quite immune to most failures, hardware or application, and power failure.

Knipfty

  • Full Member
  • ***
  • Posts: 232
Re: Frustrating Error "Autoinc Fields are read-only"
« Reply #7 on: July 29, 2012, 02:05:05 am »
Well I haven't figure out the why, but I got it all to work.  I'd like to know if anyone has any kind of explanation.

Lazarus/FPC/Adantage DB were complaining when I set up multiple master/slave relationships on the TTables component.  The strange part (and this is what threw me), was that while the master table was empty, everything was fine.  It was only after I added a master record that the errors started appearing.  No matter how I played with the properties on the TTables component, the error was still there.  I even dropped the tables in question and rebuilt them from scratch to no avail.

Since it was complaining about the fields being autoinc and I needed a primary key, I reworked my code to generate a GUID string of 38 bytes.  Fortunately, this was already part of FPC.

Code: [Select]
     
Result := CreateGUID(GUID);
AdsMtgTableEE.FieldByName('kid').AsString := GuidToString(GUID);

The above generates and assigns the key value.

So instead of relying on the DB to generate the unique key for each table, I do it now.  I also get the benefit of having globally unique keys which may come in handy when I write interfaces to other software.  The only real downside is that my keys went from 4 bytes to 38 bytes.

So there is some sort of interaction going on that I do not understand, but have worked around.

Thanks everyone for your suggestions,

Knipfty
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: [SOLVED]Frustrating Error "Autoinc Fields are read-only"
« Reply #8 on: July 30, 2012, 12:12:03 pm »
Knipfty,

In a properly worked database, there should never be child (detail) rows without a parent (master).

Knipfty

  • Full Member
  • ***
  • Posts: 232
Re: [SOLVED]Frustrating Error "Autoinc Fields are read-only"
« Reply #9 on: July 30, 2012, 04:16:49 pm »
Elmug,

I have over 20 years of database experience to my credit.  I've designed databases with 100's of tables for client/server applications used  by large corps.  I know that.

The issue is that when I add a record to a master table Laz/FPC/Advantage (I really can't tell where the error is coming from) is complaining about autoinc field not being readonly.

SO I simply stopped using the autoinc capability of the DB and swapped in my own key code generation.  Problem solved.

Knipfty
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

Lacak2

  • Guest
Re: [SOLVED]Frustrating Error "Autoinc Fields are read-only"
« Reply #10 on: July 31, 2012, 07:46:26 am »
It seems to me, that your original problem may be related to bug 17624, which was fixed some months ago. So you should upgrade (use) FPC to 2.6.1 or 2.7.1

Knipfty

  • Full Member
  • ***
  • Posts: 232
Re: [SOLVED]Frustrating Error "Autoinc Fields are read-only"
« Reply #11 on: August 02, 2012, 08:56:22 pm »
Hi Lacak2,

I never looked at bug tracker before.  (Now I have something else to look at 8-)).

That does somewhat describe what I was going thru, though not perfectedly.  AS I was setting up a Master/Slave relation ship between several tables.  But for all I know, this was doing the same thing in trying to assign teh key value to an autoinc field.

As noted above, I have changed over to GUID keys.  When I get a chance, I can run a small test with the latest builds I am now getting via FPCup (Thanks BigChimp).

And Thank you Lacak2 for pointing this out to me.  My wife is going out of town this weekend for 5 days.  Which means I will have a lot of time on my hands to play with Lazarus...

Knipfty
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

 

TinyPortal © 2005-2018