Created
July 3, 2019 16:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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