Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: autoinc in cursors

$
0
0
Re: autoinc in cursors
FoxInCloud
Re: autoinc in cursors
Jun. 3, 2013
04:48 am
3ST0AB6WNShow this entire thread in new window
Gratar Image based on email address
From:FoxInCloud support
To:Tuvia Vinitsky
{updated}

Hi Tuvia,

After further research we came up with the following code updates;
could you review and provide feedback on your testing?

If this is OK for cursors, we'll need to implement for restoration of buffered data in aliases having autoincremented fields.

Thanks,

* ------------------------------------------------------------HIDDENPROCEDURE PropsRestore_DS_Alias_data_rowsLPARAMETERS tcTypeIF m.tcType == 'C'&& seul le contenu des curseurs est à restaurerIFIsReadonly() && {V 1.26} ne devrait plus jamais arriver puisque this.PropsRestore_DS_Alias_cols() force à READWRITE this.Warning(Textmerge([() - ] + ICase(; m.this.cLangUser = 'fr', [Le curseur '' est en lecture seule - veuillez utiliser la clause INTO CURSOR avec la clause READWRITE],; && copy-paste this line to add another language support[Cursor '' is read-only - please use clause INTO CURSOR with the READWRITE clause]; )))ELSELOCAL loRows AS MSXML2.DOMDocument, lcCursor, lcAlterPre, lcAlterPost loRows = this.PropsRestore_DS_oChildNode('rows') lcCursor = this.PropsRestore_DS_Alias_cXMLcursor(m.loRows.XML, @m.lcAlterPre, @m.lcAlterPost)ZAP&& nécessite CursorGetProp("Buffering") <= 3&lcAlterPreAPPENDFROMDbf(m.lcCursor)&lcAlterPost USE IN (m.lcCursor) ENDIFENDIF

* ------------------------------------------------------------HIDDENPROCEDURE PropsRestore_DS_Alias_cXMLcursor && Curseur chargé avec les données XMLLPARAMETERS ; tcXML,; && XML to be loaded tcAlterPre,; && @ [''] ALTER TABLE command before loading cursor to turn off autoincrementing field(s) tcAlterPost && @ [''] ALTER TABLE command after loading cursor to restore autoincrementing field(s)STORE''TO tcAlterPre, tcAlterPostLOCAL laField[1], laField_[1], lnField, liField, lcField, liAutoInc; , loSelect, lcAlias; , lcResult#IF .F. && AFields()&& cursor? # contents type Yes 01 Fieldname Character Yes 02 Fieldtype Character Yes 03 Fieldwidth Numeric Yes 04 Decimal places Numeric Yes 05 Null values allowed Logical Yes 06 Code page translation not allowed Logical Yes 07 Field validation expression Character Yes 08 Field validation text Character Yes 09 Fielddefaultvalue Character No 10 Table validation expression Character && Values for table-specific properties in columns 10 through 16 only appear in the first row of the array No 11 Table validation text Character No 12 Long tablename Character No 13 Inserttrigger expression Character No 14 Update trigger expression Character No 15 Deletetrigger expression Character No 16 Table comment Character Yes 17 NextValue for autoincrementing Numeric Yes 18 Stepfor autoincrementing Numeric && If the fields in the table use autoincrementing, the Step value is greater than 0#ENDIF* As CursorToXML() does not render .NULL. values,* create a cursor in which all fields have .NULL. as default value,* except autoincrementing fields which must retrieve their former sequence lnField = AFields(laField) lnField = AFields(laField_) && backupFOR liField = 1 TO m.lnField lcField = laField[m.liField, 1]IF laField[m.liField, 18]> 0 && If the fields in the table use autoincrementing, the Step value is greater than 0 laField[m.liField, 18] = 0 && turns off autoincrementing on this field, while accepting values from XML tcAlterPre = m.tcAlterPre + Textmerge(" ALTER COLUMN <<m.lcField>> I")ELSEIF laField[m.liField, 5]&& Null values allowed laField[m.liField, 9] = Evl(laField[m.liField, 9], '.NULL.') && Field default value as litteralENDIFENDIFENDFOR lcAlias = Alias() lcResult = m.lcAlias + '_XML' loSelect = abSelect(0)CREATECURSOR (m.lcResult) FROMARRAY laField && changes work areaXMLToCursor(m.tcXML, m.lcResult, 8192)&& 8192:&& Specifies that cCursorName is the name or alias of an existing table or cursor&& and imports the data from the specified XML file into an existing table or predefined cursor.&& If cCursorName contains data, the data imported from the XML file is appended to the existing data* For each autoincrementing field, calculate next value and restore auto-incrementationFOR liField = 1 TO m.lnFieldIF laField_[m.liField, 18]> 0 && If the fields in the table use autoincrementing, the Step value is greater than 0 lcField = laField_[m.liField, 1]CALCULATEMax(&lcField) TO liAutoInc tcAlterPost = m.tcAlterPost + Textmerge(" ALTER COLUMN <<m.lcField>> I AUTOINC NEXTVALUE <<m.liAutoInc + laField_[m.liField, 18]>> STEP <<laField_[m.liField, 18]>>")ENDIFENDFORIF NOT Empty(m.tcAlterPre) tcAlterPre = Textmerge([ALTER TABLE <<m.lcAlias>><<m.tcAlterPre>>])ENDIFIF NOT Empty(m.tcAlterPost) tcAlterPost = Textmerge([ALTER TABLE <<m.lcAlias>><<m.tcAlterPost>>])ENDIFRETURN m.lcResult

In order to make autoinc fields work in awserver.PropsRestore_DS_Alias_cXMLcursor you need to adjust the code as shown here:

* ------------------------------------------------------------HIDDENPROCEDURE PropsRestore_DS_Alias_cXMLcursor && Curseur chargé avec les données XMLLPARAMETERS tcXMLLOCAL laField[1], liField, lnSelect, lcResult&& CursorToXML() ne rendant pas les valeurs nulles,&& créer un curseur dont les champs sont .NULL. par défaut FOR liField = 1 TOAFields(laField)* TBV* The first row is the table itself, and if that has* triggers in it , goodnigt charlie creating and updating the cursor. So check that laField[1,13]='' laField[1,14]='' laField[1,15]=''**TBV if you try and change a autoinc field you crash the cursor creation below,* so added a check if [x,17]> 0, which for sure would indicate an autoinc field.* the two lines in the if..then are the original code*IF laField[m.liField,17]< 1 AND laField[m.liField,18]< 1 laField[m.liField, 5] = .T. && Null values allowed laField[m.liField, 9] = '.NULL.'&& Field default valueENDIF*TBV do not do this!*STORE 0 TO;* laField[m.liField, 17]; && NextValue for autoincrementing* , laField[m.liField, 18] && Step for autoincrementing *ENDFOR lcResult = Alias() + '_XML' lnSelect = Select(0)CREATECURSOR (m.lcResult) FROMARRAY laFieldSELECT (m.lnSelect)* TBV* This XMLTCURSOR will aways fail because the autoinc field throws a read-only error message.* The VFP docs say the only way around that is to set autoincerror off.LOCAL lcAINStat lcAINStat = CURSORGETPROP("AutoIncError",m.lcResult) =CURSORSETPROP("AutoIncError", "off", m.lcResult)*XMLToCursor(m.tcXML, m.lcResult, 8192)* TBV put it back =CURSORSETPROP("AutoIncError", lcAINStat, m.lcResult)*&& 8192&& Specifies that cCursorName is the name or alias of an existing table or cursor&& and imports the data from the specified XML file into an existing table or predefined cursor.&& If cCursorName contains data, the data imported from the XML file is appended to the existing dataRETURN m.lcResult



Viewing all articles
Browse latest Browse all 10393

Trending Articles