Skip to content

Commit

Permalink
fix: fixes xerial#1132 - Generated columns with stored in SQLite are …
Browse files Browse the repository at this point in the history
…not marked as generated
  • Loading branch information
sualeh committed Jun 18, 2024
1 parent 99aa8d9 commit 8dbf03f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ public ResultSet getColumns(String c, String s, String tblNamePattern, String co
colType = colType.substring(0, iStartOfDimension).trim();
}

int colGenerated = "2".equals(colHidden) ? 1 : 0;
int colGenerated = Arrays.binarySearch(new String[] {"2", "3"}, colHidden) >= 0 ? 1 : 0;

sql.append("select ")
.append(i + 1)
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/sqlite/DBMetaDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Properties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledInNativeImage;
Expand Down Expand Up @@ -490,6 +491,24 @@ public void getColumnsIncludingGenerated() throws SQLException {
assertThat(rs.next()).isFalse();
}

@Test
@DisplayName("Issue #1132 - Generated columns with stored in SQLite are not marked as generated")
public void getColumnsIncludingGeneratedStored() throws SQLException {
stat.executeUpdate("create table foo(" + "\n"
+ " id integer primary key," + "\n"
+ " bar int not null generated always as (id + 1) stored" + "\n"
+ ");");

ResultSet rs = meta.getColumns(null, null, "foo", "%");
assertThat(rs.next()).isTrue();
assertThat(rs.getString(4)).as("first column is named 'id'").isEqualTo("id");
assertThat(rs.getString(24)).as("first column is generated").isEqualTo("NO");
assertThat(rs.next()).isTrue();
assertThat(rs.getString(4)).as("second column is named 'bar'").isEqualTo("bar");
assertThat(rs.getString(24)).as("second column is generated").isEqualTo("YES");
assertThat(rs.next()).isFalse();
}

@Test
public void getColumnsWithEscape() throws SQLException {
stat.executeUpdate("create table wildcard(col1 integer, co_1 integer, 'co%1' integer)");
Expand Down

0 comments on commit 8dbf03f

Please sign in to comment.