In theory a project has a defined beginning and end (ref PMI.org). in other word it is self contained.
So there is no meaning of mixing projects. But projects can share resources.
What you are tying to do can be achieved with sharing project resources.
Once you have project for common procedures....
right click on your project/Advance/Script/Add or project/KeywordTest/Add
and can navigate to location of your file and add it
for more please read this and this
Perhaps my function can help you .. You have to adapt it to your input but after ou acces data as array named from column. Just look at the logic.
Please post your work in feedback if it works.
/** * <a id="system.stringToNamedArray"></a> * Transformer une chaîne de couples clés/valeurs en tableau nommé de nom clé et avec les lignes de valeurs * @function * @author Biache Benoit * @memberOf qa.system * Param {string} Donnees - Données à transformer * Param {boolean} [Normalize = false] - <b>true</b> alors effectue un trim des données et sur le nom du tableau le passe en majuscule * Param {string} [Separator = ";"] - Caractère séparateur des couples clé/Valeur * Param {string} [ValueSeparator = "="] - Caractère séparateur de la clé et de la Valeur * @returns {object} Renvoie <b>result.error == ""</b> si la fonction s'est exécutée sans erreur<br> et <b>result.data</b> contient les données et <b>result.count</b> contient le nombre de lignes obtenues * Si la fonction a échoué alors la valeur de l'erreur est dans <b>result.error</b> et un log de warning est créé */ qa.system.stringToNamedArray = function(Donnees = null, Normalize = false, Separator = ";", ValueSeparator = "=") { var FunctionResult = { data : [], count : 1, error : "" }; try { if (Donnees == null) throw Error("Le paramètre obligatoire Donnees n'est pas renseigné.") var fields; var temp; temp = qa.system.getTokenBySeparator(Donnees, FunctionResult.count, Separator); while (temp != "") { fields = temp.split(ValueSeparator) if (Normalize) { fields[0] = qa.system.trim(fields[0]); fields[0] = aqString.ToUpper(fields[0]); fields[1] = qa.system.trim(fields[1]); } FunctionResult.data[fields[0]] = fields[1]; FunctionResult.count++; temp = qa.system.getTokenBySeparator(Donnees, FunctionResult.count); }; } catch(e) { FunctionResult.error = qa.system.logExceptionByLevel(e, "qa.system.stringToNamedArray(" + Donnees + ", " + Normalize + ", " + Separator + "," + ValueSeparator + ")", false, "Warning"); FunctionResult.count = 0; } finally { return FunctionResult; } }
If you don't succeed, i can write the proper one but learning is better by doing ;^)
And the easiest way to fetch data from DB is using ADO, something like this (here your Sql command will be your SELECT * FROM table):
Connection = ADO.CreateConnection(); Connection.ConnectionString = ConnectionStr; Connection.Open(); Command = ADO.CreateCommand(); while (Connection.State == adStateConnecting) { aqUtils.Delay(qa.system.time.smaller); i = i + 1; if (i > 100) { throw Error("Connection not opened within 10s"); } } Command.CommandText = Sql; Command.CommandTimeout = CommandTimeout; Command.ActiveConnection = Connection; Results = Command.Execute(); ErrCount = Connection.errors.count; if (ErrCount !== 0) { for (Err = 0; Err == ErrCount; Err++){ Err = Connection.errors.item; Error = Error + Err; } Connection.Errors.Clear; throw Error; } else { if ((Results != null) && (Results.RecordCount !== 0)) { FunctionResult.Lines = Results.GetRows().toArray(); } FunctionResult.Count = Results.RecordCount; }
BenoitB Thanks much for providing some insights into this.
I see that you have a function as an array variable which has a JSON object 'functionResult'. That would store the 'data table' in 'data' array as a value. 'data' gets all the elements from 'temp' object which in turn contains row data separated by commas(,) ?
I have a few questions.
- Are you using the StringToNamedArray anywhere else to fetch the data from the array object after table is loaded into 'data' ?
- What are these params : Donnes, Normalize referring to ?
- I'm not so clear about FunctionResult.Lines = Results.GetRows().toArray(); Lines is not defined in JSON
- what's the getTokenBySeparator utility doing?
I really appreciate your help and the direction you've given. I'm still trying to understand this piece.
On the other hand, I have another function which has an ADO connection and runs a query. After that it makes a call to the routine:
dbRecordToObject(record)
This fetches single record at a time and that gets pushed to a set like this: but this is really slow
var set = conn.Execute_(exeQuery); //declare an array var elementList = []; Log.Message("INFO: set.EOF is: " +set.EOF); if(set.EOF == false){ set.MoveFirst(); while(!set.EOF) { //get the result set into the array elementList.push(dbRecordToObject(set)); set.MoveNext(); } //Closing the connection conn.Close(); return elementList;
Thank you
Al2
Related Content
- 13 years ago
- 15 years ago
- 10 years ago
- 10 years ago