Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error 26 Table has no index order set
Message
From
20/04/2014 11:54:08
 
 
To
17/04/2014 09:57:16
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01598711
Message ID:
01598846
Views:
108
Likes (1)
>Hello again Gregory
>
>I send you what you need into a Zip File
>(1) The schema (you can attach it to the message)
>(2) table layout and sample ( Only the fields necessary to create the cursors DOCUMENT , Linhas and linhasDesconto )
>(3) Example of output required.
>
>In your opinion, there is another way to create this kind of file ??
>
>Many thanks again for your interest to help me to solve the problema
>
>Best regards
>Luis Santos


Luis,

The output you have looks ok to me

There are a couple of inconsistencies between the schema and the output required

(1) fdata is a dateTime, you output it as a date
(2) the schema contains fno for Linhas. Your required output does not

So, I output fdata as dateTime and suppress fno in Linhas

Here is the code ( oh, and I use utf8)
#define true .t.
#define false .f.

function Luis()	
	
	local success
	success = true
	
	local obj
	obj = createobject('DocumentoXml')
	
	local fno, outputFile
	
	fno = 121005551
	outputFile = 'D:\tmp\Luis\Out.xml'
	
	do case
	case !m.success
	
	case !Luis_CreateCursors()
		assert false
		success = false
	
	case !m.obj.ToXml(m.outputFile, m.fno)
		assert false
		success = false
	
	endcase
	
	return m.success
	
	
endfunc
*_______________________________________________________________________________
function Luis_CreateCursors()

	&& (1) ft
	create cursor ft ;
	(	fdata	T, ;
		fno		n(10,0), ;
		no		n(10,0), ;
		nome	c(55), ;
		morada	v(55), ;
		local	v(43),;
		codpost	v(45) ;
	)
	insert into ft ;
	values ;
	(	datetime(), ;
		121005551, ;
		30314, ;
		'Beppi Suisse sarl', ;
		'Rue de Lyon 74', ;
		'', ;
		'1203 GENEVE SUISSE' ;
	)
	
	&& (2)
	create cursor fi ;
	(	fno			n(10,0),;
		linha		n(10,0), ;
		ref			v(18), ;
		design		v(60), ;
		qtt			n(11,3), ;
		epv			n(19,6), ;
		desconto	N(6, 2),;
		etiliquido	n(19,6), ;
		codpautal 	v(20), ;
		codigo 		v(40) ;
	)
	insert into fi ;
	values ;
	(	121005551, ;
		1, ;
		'', ;
		'Reserva de Cliente nº 240712 de 24.07.2012', ;
		0.000, ;
		0.000000, ;
		0.00, ;
		0.000000, ;
		'', ;
		'' ;
	)
		
	insert into fi ;
	values ;
	(	121005551, ;
		2, ;
		'2107571', ;
		'Bota Casual JUNIOR 36/41 Cx10', ;
		10.000, ;
		13.900000, ;
		10.0, ;
		125.100000, ;
		'6403911698', ;
		'2000021075719' ;
	)
	

		
		
endfunc
*_______________________________________________________________________________
define class DocumentoXml as Relation
	
	SchemaLocation = 'D:\tmp\Luis\AddTableToSchema_Nest.xsd'

*_______________________________________________________________________________
function ToXml(outputFile, fno)
	
	local success
	success = true
	
	do case
	case !m.success
	
	case !m.this.PrepareCursors(m.fno)
		assert false
		success = false
	
	case !m.this.MakeXml(m.outputFile)
		assert false
		success = false
	
	case !m.this.CloseCursors()
		assert false
		success = false
	endcase
	
	return m.success
	
endfunc
*_______________________________________________________________________________
protected function PrepareCursors(fno)

	
	local success
	success = true
	
	do case
	case !m.success
	
	case !m.this.PrepareCursors_Documento(m.fno)
		assert false
		success = false
	
	case !m.this.PrepareCursors_Linhas(m.fno)
		assert false
		success = false
	
	case !m.this.PrepareCursors_LinhasDesconto(m.fno)
		assert false
		success = false
	
	endcase
	
	
	return m.success
	
endfunc
*_______________________________________________________________________________

protected function PrepareCursors_Documento(fno)

	select	fdata, ;
			fno,;
			no, ;
			nome, ;
			morada,;
			local, ;
			codpost ;
		from ft ;
		where (fno == m.fno) ;
		order by ft.fno ;
		into cursor Documento ;

endfunc
*_______________________________________________________________________________
protected function PrepareCursors_Linhas(fno)

	select  fno, ;
			linha as nrlinha, ;
			ref, ;
			design, ;
			qtt, ;
			epv, ;
			etiliquido, ;
			codpautal , ;
			codigo ;
		from fi ;
		where	( fno = m.fno );
		order by fno, nrlinha ;
		into cursor Linhas 
	
	index on fno tag fno
	
	set fields to nrlinha, ref, design, qtt, epv, etiliquido, codpautal, codigo 
	set relation to fno into Linhas  in Documento 

endfunc
*_______________________________________________________________________________
protected function PrepareCursors_LinhasDesconto(fno)
	
	select 	linha as nrlinha, ;
			desconto ;
		from fi ;
		where	( fno == m.fno ) ;
		into cursor LinhasDesconto 
	
	index on nrlinha tag nrlinha
	set relation to nrlinha into LinhasDesconto in Linhas 
endfunc
*_______________________________________________________________________________
protected function MakeXml(outputFile)

	local success
	success = true
	
	local obj
	
	do case
	case !m.success
	
	case !m.this.GetXmlAdapter(@m.obj)
		assert false
		success = false
	
	case !m.this.SetXmlAdapterProperties(m.obj)
		assert false
		success = false
	
	case empty(m.obj.ToXml(m.outputFile, m.this.SchemaLocation , true))
		assert false
		success = false
		
	endcase
	
	return m.success
	
endfunc
*_______________________________________________________________________________
protected function GetXmlAdapter(obj)
	
	obj = null
	
	try
		obj = createobject('XmlAdapter')
	
	catch
	
	endtry
	
	return vartype(m.obj) == T_OBJECT
endfunc
*_______________________________________________________________________________
protected function SetXmlAdapterProperties(obj)
	
	with m.obj
		.FormattedOutput = false
		.PreserveWhiteSpace = false
		.RespectNesting = true
		.RespectCursorCP = true
		.UTF8Encoded = true
		.XMLSchemaLocation =''
		= .AddTableSchema([Documento])
		= .AddTableSchema([Linhas])
		= .AddTableSchema([LinhasDesconto])

	endwith
	
	if( !m.this.SuppressTableField(m.obj, 'Documento', 'fno') )
		assert false
		return false
	endif
endfunc
*_______________________________________________________________________________
function SuppressTableField(obj, tablename, fieldname)

	local success
	success = true
	
	local tableObj
	
	do case
	case !m.success
	
	case !m.this.GetTable(@m.tableObj, m.obj, 'Linhas')
		assert false
		success = false
	
	case !m.tableObj.Fields.Remove(m.this.stringToUtf16(m.fieldname))
		assert false
		success = false
	endcase
	
	return m.success
	
endfunc
*_______________________________________________________________________________
protected  function GetTable(tableObj, obj, tablename)

	
	tableObj = m.obj.Tables(m.this.stringToUtf16(m.tablename))
	
	
	return true
endfunc
*_______________________________________________________________________________
protected function CloseCursors()

	use in select('Documento')
	use in select('Linhas')
	use in select('LinhasDesconto')
endfunc
*_______________________________________________________________________________
protected  function stringToUtf16(s)

	return strconv(m.s, 5, cpcurrent(), 1)
endfunc
*_______________________________________________________________________________
enddefine
*_______________________________________________________________________________
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform