Skip to content

Problem using AsString() and other functions with IN params in order expression #1933

@cpyrgas

Description

@cpyrgas

Strange one, when trying to use AsString() in an order expression, somehow FieldPut() is called in the process, and this leads to a runtime error that the dbf must be locked (if it's opened shared).

I noticed that when I use custom functions, I get the same problem when they have IN parameters. When using AS parameters instead, it works fine.

I do realize using AsString() in index expressions is not a good idea, was only a test for something else and found this bizarre issue.

FUNCTION Start() AS VOID
	LOCAL cDbf AS STRING
	cDbf := "c:\dbf\test_IN"

	DbCreate(cDbf, {{"FLD1","N",10,0}})
	? DbUseArea(TRUE,,cDbf,,TRUE)
	DbAppend(); FieldPut(1,1)
	DbAppend(); FieldPut(1,3)
	DbAppend(); FieldPut(1,2)
	
	? DbCreateIndex(cDbf + "_ord1", "Str(FLD1)") // OK
	? DbCreateIndex(cDbf + "_ord2", "AsStringAS(FLD1)") // OK

	? DbCreateIndex(cDbf + "_ord3", "AsString(FLD1)") // error
	? DbCreateIndex(cDbf + "_ord4", "AsStringIN(FLD1)") // error

// followin functions also have an IN param and cause the same problem
	? DbCreateIndex(cDbf + "_ord5", "__Str(FLD1)") // error
	? DbCreateIndex(cDbf + "_ord6", "Str1(FLD1)") // error
	? DbCreateIndex(cDbf + "_ord7", "AsHexString(FLD1)") // error

FUNCTION AsStringAs(u AS USUAL) AS STRING
RETURN Str(u)
FUNCTION AsStringIn(u IN USUAL) AS STRING
RETURN Str(u)
Description :	Lock required (Record has to be locked)
Subsystem :	DBFNTX
GenCode :	EG_UNLOCKED Lock required
SubCode :	1122 Record has to be locked
FuncSym :	__FieldSet
Severity :	ES_ERROR
Can Default :	True
Can Retry :	False
Can Substitute :	False
FileName :	c:\dbf\test_IN.DBF
Stack Trace :	
 DBF:GOHOT (Line: 0)
 DBFNTX:GOHOT (Line: 0)
 DBF:PUTVALUE (Line: 0)
 COREDB:<>C__DISPLAYCLASS49_0:<FIELDPUT>B__0 (Line: 0)
 COREDB:DO (Line: 0)
 COREDB:FIELDPUT (Line: 0)
 __FIELDSET (Line: 0)
 {||ASSTRING(FLD1)} (Line: 0)
 MACROCODEBLOCK:EVAL (Line: 0)
 CODEBLOCK:EVALBLOCK (Line: 0)
 WORKAREA:EVALBLOCK (Line: 0)
 DBF:EVALBLOCK (Line: 0)
 NTXORDER:_GETEXPRESSIONVALUE (Line: 0)
 NTXORDER:_CREATEINDEX (Line: 0)
 NTXORDER:CREATE (Line: 0)
 NTXORDERLIST:CREATE (Line: 0)
 DBFNTX:ORDERCREATE (Line: 0)
 COREDB:<>C__DISPLAYCLASS69_0:<ORDCREATE>B__0 (Line: 0)
 COREDB:DO (Line: 0)
 COREDB:ORDCREATE (Line: 0)
 ORDCREATE (Line: 0)
 DBCREATEINDEX (Line: 0)
 START (Line: 73)


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions