forked from microsoft/mssql-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamTabName.java
57 lines (46 loc) · 1.8 KB
/
StreamTabName.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Microsoft JDBC Driver for SQL Server
*
* Copyright(c) Microsoft Corporation All rights reserved.
*
* This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
/**
* StreamTabName interprets the data stream from a TABNAME TDS token
*
*/
final class StreamTabName extends StreamPacket {
private TDSReader tdsReader;
private TDSReaderMark tableNamesMark;
StreamTabName() {
super(TDS.TDS_TABNAME);
}
void setFromTDS(TDSReader tdsReader) throws SQLServerException {
if (TDS.TDS_TABNAME != tdsReader.readUnsignedByte())
assert false : "Not a TABNAME token";
this.tdsReader = tdsReader;
int tokenLength = tdsReader.readUnsignedShort();
tableNamesMark = tdsReader.mark();
tdsReader.skip(tokenLength);
}
void applyTo(Column[] columns,
int numTables) throws SQLServerException {
TDSReaderMark currentMark = tdsReader.mark();
tdsReader.reset(tableNamesMark);
// Read in all of the multi-part table names. The number of table
// names to expect is determined in advance. It is computed as a side
// effect of processing the COLINFO token that preceeds this TABNAME token.
SQLIdentifier[] tableNames = new SQLIdentifier[numTables];
for (int i = 0; i < numTables; i++)
tableNames[i] = tdsReader.readSQLIdentifier();
// Apply the table names to their appropriate columns
for (int i = 0; i < columns.length; i++) {
Column col = columns[i];
if (col.getTableNum() > 0)
col.setTableName(tableNames[col.getTableNum() - 1]);
}
tdsReader.reset(currentMark);
return;
}
}