コード例 #1
0
ファイル: sqlbatch.php プロジェクト: google-code-backups/eude
function sql($query)
{
    if (DEBUG_PLAIN) {
        return FB::log($query);
    }
    if (SCRIPT_IN) {
        return DataEngine::sql($query);
    }
    $sql = str_replace('SQL_PREFIX_', SQL_PREFIX_, $query);
    $result = mysql_query($sql) or sqlerror($query);
}
コード例 #2
0
ファイル: sqlbatch.php プロジェクト: google-code-backups/eude
function sql($sql)
{
    $sql = str_replace('%%username%%', mysql_real_escape_string(gpc_esc($_POST['username'])), $sql);
    $sql = str_replace('%%password%%', mysql_real_escape_string(gpc_esc($_POST['password'])), $sql);
    $empire = gpc_esc($_POST['empire']);
    $sql = str_replace('%%empirename%%', mysql_real_escape_string($empire), $sql);
    $sql = str_replace('%%empirenamelen%%', p_strlen($empire), $sql);
    $board = gpc_esc($_POST['board']);
    $sql = str_replace('%%boardname%%', mysql_real_escape_string($board), $sql);
    $sql = str_replace('%%boardnamelen%%', p_strlen($board), $sql);
    $sql = str_replace('SQL_PREFIX_', SQL_PREFIX_, $sql);
    FB::log($sql);
    if (!DEBUG_PLAIN) {
        $result = mysql_query($sql) or sqlerror($sql);
    }
}
コード例 #3
0
function equation2mg($exp)
{
    # split operator
    $exp = trim($exp);
    if (!$exp) {
        return '';
    }
    ### check for normal
    if (preg_match('/(\\w+).*?([<>=!]+)(.*)/i', $exp, $matches)) {
        $operator = $matches[2];
        ### check for is null and such
    } else {
        if (preg_match('/([^ ]+) +?(is +?null|is +?not +?null|like) *?(.*)/i', $exp, $matches)) {
            $operator = strtolower($matches[2]);
            #print_r ($matches);
            #print ($exp . " $operator <br/>");
        }
    }
    $matches[3] = trim($matches[3]);
    if ($operator == '=') {
        $mg_equation = "{ " . $matches[1] . " : " . $matches[3] . " }";
    } elseif ($operator == '<') {
        $mg_equation = "{  " . $matches[1] . " : { '\$lt' : {$matches['3']} } }";
    } elseif ($operator == '>') {
        $mg_equation = "{  " . $matches[1] . " : { '\$gt' : {$matches['3']} } }";
    } elseif ($operator == '<=') {
        $mg_equation = "{  " . $matches[1] . " : { '\$lte' : {$matches['3']} } }";
    } elseif ($operator == '>=') {
        $mg_equation = "{  " . $matches[1] . " : { '\$gte' : {$matches['3']} } }";
    } elseif ($operator == 'is null') {
        $mg_equation = "{  " . $matches[1] . " : null }";
    } elseif ($operator == '!=') {
        $mg_equation = "{  " . $matches[1] . " : { '\$ne' : {$matches['3']} } }";
    } elseif ($operator == 'is not null') {
        $mg_equation = "{  " . $matches[1] . " : { '\$ne' : null } }";
    } elseif ($operator == 'like') {
        $a = $matches[1];
        $b = $matches[3];
        if (!preg_match('/[%_]/', $b)) {
            $mg_equation = "{ {$a} : {$b} }";
        } else {
            $b = trim($b);
            $b = preg_replace("/(^['\"]|['\"]\$)/", "", $b);
            # 'text' -> text  or "text" -> text
            if (!preg_match("/^%/", $b)) {
                $b = "^" . $b;
            }
            # handles like 'text%' -> /^text/
            if (!preg_match("/%\$/", $b)) {
                $b .= "\$";
            }
            # handles like '%text' -> /^text$/
            $b = preg_replace("/%/", ".*", $b);
            $b = preg_replace("/_/", ".", $b);
            $mg_equation = "{ {$a} : /{$b}/}";
        }
        #print ($exp . " $operator <br/>");
        #sqlerror ("unsupported");
        #$mg_equation = "{  " . $matches[1] . " : { '\$ne' : null } ";
    } else {
        sqlerror("Unknown operator '{$operator}' :  {$exp}");
    }
    return $mg_equation;
}
コード例 #4
0
ファイル: index.php プロジェクト: priyadharshan/sqltomongodb
                        $rowstofind = $skipvalue;
                    } else {
                        $mg_limit = ".limit({$value})";
                        $skipvalue = $value;
                        $rowstofind = $skipvalue;
                    }
                }
                if ($rowstofind == 1) {
                    $findcommand = "findOne";
                } else {
                    $findcommand = "find";
                }
            }
            $mongo = "db.{$mg_collection}.{$findcommand}( {$mg_where}{$mg_fields} ){$mg_distinct}{$mg_count}{$mg_skip}{$mg_sort}{$mg_limit}";
        } else {
            sqlerror("unsupported querytype for the time being: " . $sql['querytype']);
        }
    }
    echo "<pre>";
    #print_r($sql);
    echo "</pre>";
}
if (!$r_sql) {
    $r_sql = "select a,b from table where c<=4 and (a=1 or (b=2 and c='something'))";
}
function sqlerror($msg)
{
    echo "<br/><b>{$msg}</b><br/>\n";
}
$head = <<<eof
<script type="text/javascript">