Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help - What am I doing wrong with this primary key
Message
De
06/12/2000 05:15:40
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
06/12/2000 04:39:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00449457
Message ID:
00449842
Vues:
15
Mark,
What Trey said is right. Here is a long posting to demonstrate :
CLOSE DATA ALL
CREATE DATABASE 'TESTPK.DBC'

CREATE TABLE 'IDS.DBF' NAME 'IDS' (TABLE C(15) NOT NULL, ;
                  NEXTID I NOT NULL)
INDEX ON TABLE TAG TABLE

CREATE TABLE 'DUMMYTEST.DBF' NAME 'DUMMYTEST' ;
  (PKID I NOT NULL DEFAULT newid("DUMMYTEST"), MYFIELD C(10) NOT NULL)
INDEX ON PKID TAG PKID

CREATE SQL VIEW "VIEW1" ; 
   AS SELECT * FROM testpk!dummytest
DBSetProp('VIEW1', 'View', 'UpdateType', 1)
DBSetProp('VIEW1', 'View', 'WhereType', 3)
DBSetProp('VIEW1', 'View', 'FetchMemo', .T.)
DBSetProp('VIEW1', 'View', 'SendUpdates', .T.)
DBSetProp('VIEW1', 'View', 'UseMemoSize', 255)
DBSetProp('VIEW1', 'View', 'FetchSize', 100)
DBSetProp('VIEW1', 'View', 'MaxRecords', -1)
DBSetProp('VIEW1', 'View', 'Tables', 'testpk!dummytest')
DBSetProp('VIEW1', 'View', 'Prepared', .F.)
DBSetProp('VIEW1', 'View', 'CompareMemo', .T.)
DBSetProp('VIEW1', 'View', 'FetchAsNeeded', .F.)
DBSetProp('VIEW1', 'View', 'FetchSize', 100)
DBSetProp('VIEW1', 'View', 'Comment', "")
DBSetProp('VIEW1', 'View', 'BatchUpdateCount', 1)
DBSetProp('VIEW1', 'View', 'ShareConnection', .F.)

*!* Field Level Properties for VIEW1
* Props for the VIEW1.pkid field.
DBSetProp('VIEW1.pkid', 'Field', 'KeyField', .T.)
DBSetProp('VIEW1.pkid', 'Field', 'Updatable', .T.)
DBSetProp('VIEW1.pkid', 'Field', 'UpdateName', 'testpk!dummytest.pkid')
DBSetProp('VIEW1.pkid', 'Field', 'DataType', "I")
DBSetProp('VIEW1.pkid', 'Field', 'DefaultValue', "NewId('DUMMYTEST')")
* Props for the VIEW1.myfield field.
DBSetProp('VIEW1.myfield', 'Field', 'KeyField', .F.)
DBSetProp('VIEW1.myfield', 'Field', 'Updatable', .T.)
DBSetProp('VIEW1.myfield', 'Field', 'UpdateName', 'testpk!dummytest.myfield')
DBSetProp('VIEW1.myfield', 'Field', 'DataType', "C(10)")
And this goes to stored procedures :
function NewId
	LPARAMETERS tcAlias
	LOCAL lcAlias
	* Uppercase Alias name
	lcAlias = upper(iif(parameters() = 0, alias(), tcAlias))
	* Lock reprocess - try once
	SET REPROCESS TO 1
	IF !USED("IDS")
		USE ids IN 0
	ENDIF
	* If no entry yet create and return 1
	IF !SEEK(lcAlias, "Ids", "table")
		INSERT into ids (Table, NextId) values (lcAlias,1)
		RETURN ids.NextId
	ENDIF
	* Lock, increment id, unlock, return nextid value
	DO while !RLOCK('ids')
		* Delay before next lock trial
		lnStart = seconds()
		DO while seconds()-lnStart < 0.01
		ENDDO
	ENDDO
	* Increment
	REPLACE ids.NextId WITH ids.NextId + 1 in 'ids'
	UNLOCK in 'ids'
	RETURN ids.NextId
DBC and view ready. Now test code :
open data TestPk
use view1 && Not really necessary - to mimic opening in DE
insert into View1 (myField) values ('A')
insert into View1 (myField) values ('B')
insert into View1 (myField) values ('C')
insert into View1 (myField) values ('D')
insert into View1 (myField) values ('')
tableupdate()
close all
clear all
use DummyTest
browse
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform