Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat(database): add parse for sql
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 31, 2022
1 parent 3b66265 commit 1fcb58d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
@@ -1,6 +1,5 @@
package org.archguard.scanner.sourcecode.database

import chapi.domain.core.CodeCall
import chapi.domain.core.CodeDataStruct
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
Expand All @@ -24,7 +23,7 @@ class MysqlAnalyser {
function.Annotations.forEach {
if(it.Name == "SqlQuery") {
val value = it.KeyValues[0].Value
sqls += value.removeSuffix("\"").removePrefix("\"")
sqls += sqlify(value)
}
}

Expand All @@ -42,4 +41,13 @@ class MysqlAnalyser {

return logs
}

private fun sqlify(value: String): String {
var text = removeBeginEndQuotes(value)
text = removePlus(text)
return text
}

private fun removePlus(text: String) = text.replace("\"+\"", "")
private fun removeBeginEndQuotes(value: String) = value.removeSuffix("\"").removePrefix("\"")
}
Expand Up @@ -19,6 +19,6 @@ internal class MysqlAnalyserTest {
}

assertEquals(4, logs.size)
assertEquals("select source_package as sourcePackage, source_class as sourceClass, source_method as sourceMethod,\"+\" target_url as targetUrl, target_http_method as targetHttpMethod, system_id as systemId\"+\" from container_demand where system_id = :systemId", logs[0].Sql[0])
assertEquals("select source_package as sourcePackage, source_class as sourceClass, source_method as sourceMethod, target_url as targetUrl, target_http_method as targetHttpMethod, system_id as systemId from container_demand where system_id = :systemId", logs[0].Sql[0])
}
}

0 comments on commit 1fcb58d

Please sign in to comment.