diff --git a/Global.cpp b/Global.cpp index 11aba57..d7c7ca7 100644 --- a/Global.cpp +++ b/Global.cpp @@ -24,13 +24,9 @@ namespace jet { } void Global::addSession(coreutils::MString sessionId, __mysql *mysql) { - std::cout << "sessionId: " << sessionId << std::endl; if(sessionExists(sessionId)) coreutils::Exception("sessionid already exists."); sessions[sessionId] = mysql; - - std::cout << "::count: " << sessions.size() << std::endl; - std::cout << "::" << sessionId << std::endl; } void Global::removeSession(coreutils::MString sessionId) { @@ -101,7 +97,7 @@ namespace jet { void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map &lvariables) { while(!variable.ifNext("]")) { - name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"); + name << variable.getTokenInclude("#?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"); if(variable.ifNext(";")) { renderVariableName(variable, modifier, modifier, lvariables); return; @@ -111,7 +107,7 @@ namespace jet { name << getVariable(variable, lvariables); else if(variable.ifNext("]")) return; - else if(!variable.ifNextInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-")) + else if(!variable.ifNextInclude("#?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-")) throw coreutils::Exception("invalid variable name."); } return; diff --git a/__for.cpp b/__for.cpp index c4d16cf..ef42cc9 100644 --- a/__for.cpp +++ b/__for.cpp @@ -23,8 +23,14 @@ namespace jet { for(double ix = counter; ix <= variables["end"].asDouble(); ix += variables["step"].asDouble()) { variables["end"].reset(); variables["step"].reset(); - if(nameDefined) - variables[variables["name"]] = ix; + if(nameDefined) { + if(!variableDefined("scope") || (variables["scope"] == "global")) + global.variables[variables["name"]] = ix; + else if(variables["scope"] == "local") + local->variables[variables["name"]] = ix; + else if(variables["scope"] == "parent") + parent->local->variables[variables["name"]] = ix; + } processContainer(container); container.reset(); } diff --git a/__mysql.cpp b/__mysql.cpp index a751e1d..4a1c435 100644 --- a/__mysql.cpp +++ b/__mysql.cpp @@ -30,8 +30,6 @@ namespace jet { if(!mysql) throw coreutils::Exception("database and host parameters are not valid."); - - std::cout << "mysql: " << mysql << std::endl; processContainer(container); @@ -63,9 +61,23 @@ namespace jet { } coreutils::ZString __mysql::getColumnValue(coreutils::ZString column) { - if(column == "#") - return NbrOfRows; MYSQL_FIELD *field; + if(column == "?#") { + nbrOfColumns = (int)qFields; + return nbrOfColumns; + } else if(column.ifNext("#")) { + if(column.eod()) { + nbrOfRows = (int)mysql_num_rows(result); + return nbrOfRows; + } else { + std::cout << "[" << column.unparsed() << "]" << std::endl; + int index = column.asInteger(); + std::cout << "integer: " << index << std::endl; + field = mysql_fetch_field_direct(result, index - 1); + return coreutils::ZString(field->name); + } + } + for(int ix = 0; ix < qFields; ++ix) { field = mysql_fetch_field_direct(result, ix); if(column.equals((char *)field->name)) { diff --git a/__mysql.h b/__mysql.h index 1759065..07652eb 100644 --- a/__mysql.h +++ b/__mysql.h @@ -28,7 +28,8 @@ namespace jet { unsigned int qFields; coreutils::MString sessionId; - coreutils::MString NbrOfRows = "0"; + coreutils::MString nbrOfRows = "0"; + coreutils::MString nbrOfColumns = "0"; }; diff --git a/tests/testdb.jet b/tests/testdb.jet index ba6ab88..790257e 100755 --- a/tests/testdb.jet +++ b/tests/testdb.jet @@ -5,5 +5,10 @@ $[1.id] $[1.text] $[1.value] +Number of rows: $[1.#] +Number of columns: $[1.?#] + +Field $[ix] is $[1.#$[ix]] +