Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CursorAdapter and PostgreSQL Problem
Message
 
To
22/10/2003 23:53:53
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00840453
Message ID:
00841633
Views:
28
Hi Aleksey

I will try your code and report back to you on Monday when I return to the client's site for further testing.

Thanks
Simon


>Hi Simon,
>
>I don't have any problem to make it work for SQL Server:
>
>CLOSE DATABASES ALL
>CLEAR
>
>con=SQLCONNECT("LocalServer")
>
>IF con<1
>	?"Failed to connect!!!"
>	AERROR(aerrs)
>	DISPLAY MEMORY LIKE aerrs
>	RETURN
>ENDIF
>
>IF 1!=SQLEXEC(con,[create table uptable(id int, "desc" int)])
>	?"Failed to create table!!!"
>	AERROR(aerrs)
>	DISPLAY MEMORY LIKE aerrs
>	RETURN
>ENDIF
>
>LOCAL oCA as CursorAdapter
>
>oCA=CREATEOBJECT("CAPrintInsCommand")
>oCA.Alias="CATest"
>oCA.DataSourceType="ODBC"
>oCA.DataSource=con
>oCA.SelectCmd="select * from uptable"
>
>IF !oCA.CursorFill()
>	?"CursorFill failed!!!"
>	AERROR(aerrs)
>	DISPLAY MEMORY LIKE aerrs
>ELSE
>
>	oCA.Tables=["uptable"]
>	oCA.KeyFieldList="id"
>	oCA.UpdatableFieldList = "id, desc"
>	oCA.UpdateNameList=[id "uptable"."id",desc "uptable"."desc"]
>
>	INSERT INTO CATest VALUES (1,1)
>
>	IF !TABLEUPDATE(.F.)
>		?"TABLEUPDATE failed!!!"
>		AERROR(aerrs)
>		DISPLAY MEMORY LIKE aerrs
>	ENDIF	
>
>	oCA.Tables=[uptable]
>	oCA.KeyFieldList="id"
>	oCA.UpdatableFieldList = "id, desc"
>	oCA.UpdateNameList=[id uptable.id,desc uptable."desc"]
>
>	INSERT INTO CATest VALUES (2,2)
>
>	IF !TABLEUPDATE(.F.)
>		?"TABLEUPDATE failed!!!"
>		AERROR(aerrs)
>		DISPLAY MEMORY LIKE aerrs
>	ENDIF	
>	>	TABLEREVERT(.T.)
>ENDIF
>
>CLOSE TABLES
>
>SQLEXEC(con,[select * from uptable],"CurrentState")
>SELECT CurrentState
>LIST
>
>
>SQLEXEC(con,[drop table uptable])
>SQLDISCONNECT(con)
>
>return
>
>
>
>DEFINE CLASS CAPrintInsCommand AS CursorAdapter
>	PROCEDURE BeforeInsert
>		LPARAMETERS cFldState, lForce, cInsertCmd
>		?
>		? PROGRAM()
>		? "cInsertCmd=",cInsertCmd
>		?
>	ENDPROC
>ENDDEFINE
>
>
>Here is the output (the code prints Insert commands executed by the CursorAdapter):
>
>
>
>CAPRINTINSCOMMAND.BEFOREINSERT
>cInsertCmd= INSERT INTO "uptable" ("id","desc") VALUES (?catest.id,?catest.desc)
>
>
>CAPRINTINSCOMMAND.BEFOREINSERT
>cInsertCmd= INSERT INTO uptable (id,"desc") VALUES (?catest.id,?catest.desc)
>
>Record#           ID        DESC
>      1            1           1
>      2            2           2
>
>
>Try to accommodate this code for your connection and table. If it still doesn't work, please post all the code as well as the output.
>
>Thanks,
>Aleksey.
>
>
>
>
>
>>Hi Aleksey
>>
>>I am sorry I fogot to mention that I had already set the UpdatableFieldList.
>>
>>Simon
>>
>>>Hi Simon,
>>>
>>>You have to set UpdatableFieldList property as well. Try to set it as follows:
>>>
>>>UpdatableFieldList = "id, desc"
>>>
>>>
>>>Just a tip for troubleshooting: you can use BeforeInsert event to check if command is generated and how does it look like.
>>>
>>>Thanks,
>>>Aleksey.
>>>
>>>>Hi Alexsey
>>>>
>>>>I have not yet been able to make the automatic Insert work. I tried using
>>>>
>>>>KeyFieldList="id"
>>>>Tables=["uptable"]
>>>>UpdateNameList=[id "uptable"."id",desc "uptable"."desc"]
>>>>
>>>>and
>>>>
>>>>KeyFieldList="id"
>>>>Tables="uptable"
>>>>UpdateNameList=[id uptable."id",desc uptable."desc"]
>>>>
>>>>but no success.
>>>>
>>>>If I use:
>>>>
>>>>? SQLExec(1,[Insert Into "uptable" ("id","desc") values ('0000004','test')])
>>>>
>>>>it works fine. Note that single quotes are required around the values and double quotes around the field names. The table name can either be quoted or not.
>>>>
>>>>What would be the correct form of the InsertCmd if I was to create it manually.
>>>>
>>>>Thanks
>>>>Simon
>>>>
>>>>
>>>>>Hi Simon,
>>>>>
>>>>>>What confused me was that the documentation had
>>>>>>
>>>>>><remote table name>, <remote field name>,
>>>>>>
>>>>>>
>>>>>>I think it should read:
>>>>>>
>>>>>><remote table name>.<remote field name>,
>>>>>>
>>>>>>
>>>>>
>>>>>You are right, there is a mistake in help topic for UpdateNameList property.
>>>>>
>>>>>>I also do not know exactly where it mentions about the field decoration.
>>>>>>
>>>>>
>>>>>Field name decoration is not a CursorAdapter requirement, it is a backend requirement. For example, [desc] is a SQL key word that can be used in ORDER BY clause. If you want to use it as a field name, PostgreSQL requires to use quotation marks to decorate it. I this scenario, < remote field name > should be decorated field name because decoration is a part of the name and CursorAdapter has no idea whether and how the decoration should be applied (each backend has its own rules).
>>>>>
>>>>>Were you able to make it work?
>>>>>
>>>>>Thanks,
>>>>>Aleksey.
Simon White
dCipher Computing
Previous
Reply
Map
View

Click here to load this message in the networking platform