Join list of columns into a string for a SQL query
494050
def join_cols(cols):
    """"""
    return ", ".join([i for i in cols]) if isinstance(cols, (list, tuple, set)) else cols
1265565
def get_sql_select(self, columns, table, distinct=False):
        """"""
        sql = 'SELECT {0} {1} FROM {2}'
        dist = {True: 'DISTINCT', False: ''}[distinct]
        return sql.format(dist, ', '.join(columns), table)
635568
private static String join(List<Field> fields, String sep) {
	    return join(fields, sep, null);
    }
672768
def subst_quoted_strings(sql, params):
    
    parts = sql.split('@')
    params_dont_match = "number of parameters doesn' match the transformed query"
    assert len(parts) == len(params) + 1, params_dont_match  # would be internal error
    out = []
    for i, param in enumerate(params):
        out.append(parts[i])
        out.append("'%s'" % param.replace('\\', '\\\\').replace("\'", "\\\'"))
    out.append(parts[-1])
    return ''.join(out)
1180326
public static String join(List<String> list, String delim) {

		StringBuilder sb = new StringBuilder();

		String loopDelim = "";

		for (String s : list) {

			sb.append(loopDelim);
			sb.append(s);

			loopDelim = delim;
		}

		return sb.toString();
	}
296815
def clean_and_split_sql(sql: str) -> List[str]:
    
    sql_tokens: List[str] = []
    for token in sql.strip().split():
        token = token.replace('"', "'").replace("%", "")
        if token.endswith("(") and len(token) > 1:
            sql_tokens.extend(split_table_and_column_names(token[:-1]))
            sql_tokens.extend(split_table_and_column_names(token[-1]))
        else:
            sql_tokens.extend(split_table_and_column_names(token))
    return sql_tokens
802928
private static String joinWhere(List<Field> fields, String logicOperate) {
		StringBuilder sb = new StringBuilder();
		int fieldSize = fields.size();
		for(int i = 0; i < fieldSize; i++) {
			Column column = fields.get(i).getAnnotation(Column.class);
			sb.append(getColumnName(column)).append("=?");
			if(i < fieldSize - 1) {
				sb.append(" ").append(logicOperate).append(" ");
			}
		}
		return sb.toString();
	}
1318030
function (sql) {
            var columns = this.__opts.columns, ret = "";
            if (columns && columns.length) {
                ret = " (" + columns.map(
                    function (c) {
                        return c.toString(this);
                    }, this).join(this._static.COMMA_SEPARATOR) + ")";
            }
            return ret;
        }
808688
def prettifysql(sql):
    """"""
    pretty = []
    for line in sql.split('\n'):
        pretty.extend(["%s,\n" % x for x in line.split(',')])
    return pretty
339013
function columnToSQL(col) {
	var sql = "`" + col.name + "` ";

	sql += nrutil.typeToSQL(col.type);

	if (col['additional']) {
		sql += ' ' + col['additional'];
	}

	if (!col['allow_null']) {
		sql += " NOT NULL";
	}

	if (col['default_value'] !== undefined) {
		var def = col['default_value']

		sql += " DEFAULT " + nrutil.serialize(def);
	}

	if (col.type == 'primary_key') {
		sql += " PRIMARY KEY AUTO_INCREMENT";
	}

	return sql;
}
569364
public function get_sql() : string {
		if ( empty( $this->columns_to_select ) ) {
			// this should be the default behavior
			$this->columns_to_select = [ '*' ];
		}

		$from = ' FROM ' . implode( ', ', $this->from ) . ' ';

		if ( ! empty( $this->joins ) ) {
			$from .= $this->joins;
		}

		$from  .= 'WHERE ' . $this->where_clause;
		$select = 'SELECT ' . implode( ', ', $this->columns_to_select ) . $from;

		if ( ! empty( $this->group_by ) ) {
			$select .= 'GROUP BY ' . implode( ', ', $this->group_by ) . ' ';
		}

		if ( $this->order_by !== '' ) {
			$select .= 'ORDER BY ' . $this->order_by . ' ';
		}

		$select .= 'LIMIT ' . $this->limit;

		if ( $this->offset !== '' ) {
			$select .= ' OFFSET ' . $this->offset;
		}

		return $select;
	}
1110524
public String[] getColumnsBySql(Sql sql) throws SQLException {
		String columns[] = null;
		
		List<Map<String, String>> table = getMetadataBySql(sql);
		if (table != null) {
			columns = new String[table.size()];
			for (int i = 0 ; i < table.size() ; i++) {
				Map<String, String> row = table.get(i);
				if (row.containsKey("NAME") && row.get("NAME") != null) {
					columns[i] = row.get("NAME");
				}
			}
		}
		
		return columns;
	}
1029259
def get_column_declaration_list_sql(self, fields):
        
        query_fields = []

        for name, field in fields.items():
            query_fields.append(self.get_column_declaration_sql(name, field))

        return ", ".join(query_fields)
735788
function (columns, values) {
            return [this.insertSql(columns, sql.literal('VALUES ' + values.map(
                function (r) {
                    return this.literal(toArray(r));
                }, this).join(this._static.COMMA_SEPARATOR)))];
        }
402006
def joint(self, table, fields,
                    join_table, join_fields,
                    condition_field, condition_join_field,
                    join_method='left_join'):
        
        import string
        fields = map(string.strip, fields.split(','))
        select = ', '.join( ['u.{}'.format(field) for field in fields] )
        join_fields = map(string.strip, join_fields.split(','))
        join_select = ', '.join( ['v.{}'.format(field) for field in join_fields] )

        sql = "select {select}, {join_select} from {table} as u {join_method}"\
               " {join_table} as v on u.{condition_field}="\
               "v.{condition_join_field};".format(select=select,
                                                 join_select=join_select,
                                                 table=table,
                                                 join_method=join_method,
                                                 join_table=join_table,
                                                 condition_field=condition_field,
                                                 condition_join_field=condition_join_field)
        return super(PGWrapper, self).execute(sql, result=True).results
781933
def combine_columns(columns):
    
    columns_zipped = itertools.zip_longest(*columns)
    return ''.join(x for zipped in columns_zipped for x in zipped if x)
846078
def select_fields_as_sql(self):
        
        return comma_join(list(self._fields) + ['%s AS %s' % (v, k) for k, v in self._calculated_fields.items()])