Code Duplication    Length = 30-38 lines in 2 locations

class/sql_generator.php 1 location

@@ 509-538 (lines=30) @@
506
	 * 							(non-indexed will use it's original name).
507
	 * @return string
508
	 */
509
	protected function GenSqlArrayAs($param, $use_as = true, $quote = false, $tas = true)
510
	{
511
		$sql = '';
512
		if (is_array($param) && !empty($param))
513
			foreach ($param as $k=>$v)
514
			{
515
				// If there are space in $v, it need to be quoted
516
				// so always quote it.
517
				if (is_int($k))
518
				{
519
					$sql .= ", $v";
520
				}
521
				else
522
				{
523
					// table AS a
524
					// tabel AS 'a'
525
					$s_split = ($quote) ? "'" : '';
526
					$s_as = ($use_as) ? 'AS' : '';
527
					if ($tas)
528
						$sql .= ", $v $s_as $s_split{$k}$s_split";
529
					else
530
						$sql .= ", $k $s_as $s_split{$v}$s_split";
531
				}
532
			}
533
		else
534
			$sql .= ", $param";
535
		$sql = substr($sql, 2);
536
537
		return $sql;
538
	} // end of func GenSqlArrayAs
539
540
541
	/**

src/Fwlib/Db/SqlGenerator.php 1 location

@@ 244-281 (lines=38) @@
241
     *                              alias.  Eg: {tbl1, a: tbl2}
242
     * @return string
243
     */
244
    protected function genSqlArrayAs(
245
        $param,
246
        $useAs = true,
247
        $quote = false,
248
        $reverse = true
249
    ) {
250
        $sql = '';
251
        if (!empty($param) && is_array($param)) {
252
            foreach ($param as $k => $v) {
253
                // If there are space in $v, it need to be quoted, so always
254
                // quote it except number (here will not have float value).
255
                if (is_int($k)) {
256
                    $sql .= ", $v";
257
                } else {
258
                    // table AS a
259
                    // table AS 'a'
260
                    $split = ($quote) ? "'" : '';
261
                    $as = ($useAs) ? 'AS ' : '';
262
263
                    // Reverse as is only useful for particular db type
264
                    // @codeCoverageIgnoreStart
265
                    if ($reverse) {
266
                        $sql .= ", $v $as$split{$k}$split";
267
                    } else {
268
                        $sql .= ", $k $as$split{$v}$split";
269
                    }
270
                    // @codeCoverageIgnoreEnd
271
                }
272
            }
273
        } else {
274
            $sql .= ", $param";
275
        }
276
277
278
        $sql = substr($sql, 2);
279
280
        return $sql;
281
    }
282
283
284
    /**