Skip to content

Instantly share code, notes, and snippets.

@BiggerNoise
Created July 3, 2019 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BiggerNoise/63181beb270927be78772c15b2a6ffb4 to your computer and use it in GitHub Desktop.
Save BiggerNoise/63181beb270927be78772c15b2a6ffb4 to your computer and use it in GitHub Desktop.
This will allow DataGrip results to be copied to the clipboard so they can be easily used in a select query
SEP = ", "
QUOTE = "\'"
NEWLINE = System.getProperty("line.separator")
KEYWORDS_LOWERCASE = com.intellij.database.util.DbSqlUtil.areKeywordsLowerCase(PROJECT)
def record(column, dataRow) {
def value = dataRow.value(column)
if( value == null)
return
def skipQuote = value.toString().isNumber() || value == null
def stringValue = value != null ? FORMATTER.format(dataRow, column) : KW_NULL
OUT.append(skipQuote ? "": QUOTE).append(stringValue.replace(QUOTE, QUOTE + QUOTE))
.append(skipQuote ? "": QUOTE)
}
rows = ROWS.asList()
COLUMNS.eachWithIndex { column, idx ->
if(idx > 0)
OUT.append(NEWLINE)
OUT.append("(")
rows.eachWithIndex { row,ridx ->
if(ridx > 0)
OUT.append(",")
record(column, row)
}
OUT.append(")")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment