This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new e1ea758f173 ODBC: Add example to the example module (#12544)
e1ea758f173 is described below

commit e1ea758f173e7c6e6d896ff56e57e3b9c01dc17c
Author: Caideyipi <[email protected]>
AuthorDate: Mon May 20 12:35:32 2024 +0800

    ODBC: Add example to the example module (#12544)
    
    Co-authored-by: Steve Yurong Su <[email protected]>
---
 example/odbc/.gitignore                       | 344 ++++++++++++++++++++++++++
 example/odbc/ODBC-Example.sln                 |  35 +++
 example/odbc/ODBC-Example/ODBC-Example.csproj |  40 +++
 example/odbc/ODBC-Example/ODBC_Example.cs     |  84 +++++++
 example/odbc/README.md                        |  81 ++++++
 5 files changed, 584 insertions(+)

diff --git a/example/odbc/.gitignore b/example/odbc/.gitignore
new file mode 100644
index 00000000000..badd8dc039a
--- /dev/null
+++ b/example/odbc/.gitignore
@@ -0,0 +1,344 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from 
https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUNIT
+*.VisualState.xml
+TestResult.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# JustCode is a .NET coding add-in
+.JustCode
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be 
unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want 
to
+# checkin your Azure Web App publish settings, but sensitive information 
contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore 
bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- Backup*.rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were 
open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
diff --git a/example/odbc/ODBC-Example.sln b/example/odbc/ODBC-Example.sln
new file mode 100644
index 00000000000..cd65a9117c0
--- /dev/null
+++ b/example/odbc/ODBC-Example.sln
@@ -0,0 +1,35 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODBC-Example", 
"ODBC-Example\ODBC-Example.csproj", "{BFB210E1-8AB2-4E10-A8EB-41DD7016EE8D}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Any CPU = Debug|Any CPU
+               Release|Any CPU = Release|Any CPU
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {BFB210E1-8AB2-4E10-A8EB-41DD7016EE8D}.Debug|Any CPU.ActiveCfg 
= Debug|Any CPU
+               {BFB210E1-8AB2-4E10-A8EB-41DD7016EE8D}.Debug|Any CPU.Build.0 = 
Debug|Any CPU
+               {BFB210E1-8AB2-4E10-A8EB-41DD7016EE8D}.Release|Any 
CPU.ActiveCfg = Release|Any CPU
+               {BFB210E1-8AB2-4E10-A8EB-41DD7016EE8D}.Release|Any CPU.Build.0 
= Release|Any CPU
+       EndGlobalSection
+EndGlobal
diff --git a/example/odbc/ODBC-Example/ODBC-Example.csproj 
b/example/odbc/ODBC-Example/ODBC-Example.csproj
new file mode 100644
index 00000000000..65a483e02c2
--- /dev/null
+++ b/example/odbc/ODBC-Example/ODBC-Example.csproj
@@ -0,0 +1,40 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<Project Sdk="Microsoft.NET.Sdk">
+    <PropertyGroup>
+        <RootNamespace>org.apache.iotdb.odbc</RootNamespace>
+        <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
+        <Authors>Apache IoTDB</Authors>
+        <Copyright>The Apache Software Foundation</Copyright>
+        <PackageProjectUrl>https://iotdb.apache.org</PackageProjectUrl>
+        <PackageVersion>1.3.2-SNAPSHOT</PackageVersion>
+        <Title>IoTDB: Example: ODBC</Title>
+        
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
+        <OutputType>Exe</OutputType>
+        <TargetFramework>net8.0</TargetFramework>
+        <ImplicitUsings>enable</ImplicitUsings>
+        <Nullable>enable</Nullable>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <PackageReference Include="System.Data.Odbc" Version="8.0.0" />
+    </ItemGroup>
+
+</Project>
diff --git a/example/odbc/ODBC-Example/ODBC_Example.cs 
b/example/odbc/ODBC-Example/ODBC_Example.cs
new file mode 100644
index 00000000000..5d7c76d41ab
--- /dev/null
+++ b/example/odbc/ODBC-Example/ODBC_Example.cs
@@ -0,0 +1,84 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//      https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+using System.Data.Odbc;
+
+// Get a connection
+var dbConnection = new OdbcConnection("DSN=ZappySys JDBC Bridge");
+dbConnection.Open();
+
+// Execute the write commands to prepare data
+var dbCommand = dbConnection.CreateCommand();
+dbCommand.CommandText = "insert into root.Keller.Flur.Energieversorgung(time, 
s1) values(1715670861634, 1)";
+dbCommand.ExecuteNonQuery();
+dbCommand.CommandText = "insert into root.Keller.Flur.Energieversorgung(time, 
s2) values(1715670861634, true)";
+dbCommand.ExecuteNonQuery();
+dbCommand.CommandText = "insert into root.Keller.Flur.Energieversorgung(time, 
s3) values(1715670861634, 3.1)";
+dbCommand.ExecuteNonQuery();
+
+// Execute the read command
+dbCommand.CommandText = "SELECT * FROM root.Keller.Flur.Energieversorgung";
+var dbReader = dbCommand.ExecuteReader();
+
+// Write the output header
+var fCount = dbReader.FieldCount;
+Console.Write(":");
+for(var i = 0; i < fCount; i++)
+{
+    var fName = dbReader.GetName(i);
+    Console.Write(fName + ":");
+}
+Console.WriteLine();
+
+// Output the content
+while (dbReader.Read())
+{
+    Console.Write(":");
+    for(var i = 0; i < fCount; i++) 
+    {
+        var fieldType = dbReader.GetFieldType(i);
+        switch (fieldType.Name)
+        {
+            case "DateTime":
+                var dateTime = dbReader.GetInt64(i);
+                Console.Write(dateTime + ":");
+                break;
+            case "Double":
+                if (dbReader.IsDBNull(i)) 
+                {
+                    Console.Write("null:");
+                }
+                else 
+                {
+                    var fValue = dbReader.GetDouble(i);
+                    Console.Write(fValue + ":");
+                }   
+                break;
+            default:
+                Console.Write(fieldType.Name + ":");
+                break;
+        }
+    }
+    Console.WriteLine();
+}
+
+// Shut down gracefully
+dbReader.Close();
+dbCommand.Dispose();
+dbConnection.Close();
diff --git a/example/odbc/README.md b/example/odbc/README.md
new file mode 100644
index 00000000000..5f62ce6953c
--- /dev/null
+++ b/example/odbc/README.md
@@ -0,0 +1,81 @@
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+        http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+
+# ODBC
+With IoTDB JDBC, IoTDB can be accessed using the ODBC-JDBC bridge. The example 
program in "odbc" can write and read data through ODBC using the bridge.
+
+## Dependencies
+* IoTDB-JDBC's jar-with-dependency package
+* ODBC-JDBC bridge (e.g. ZappySys JDBC Bridge)
+
+## Deployment
+### Preparing JDBC package
+Download the source code of IoTDB, and execute the following command in root 
directory:
+```shell
+mvn clean package -pl iotdb-client/jdbc -am -DskipTests -P 
get-jar-with-dependencies
+```
+Then, you can see the output 
`iotdb-jdbc-1.3.2-SNAPSHOT-jar-with-dependencies.jar` under 
`iotdb-client/jdbc/target` directory.
+
+### Preparing ODBC-JDBC Bridge
+*Note: Here we only provide one kind of ODBC-JDBC bridge as the instance. 
Readers can use other ODBC-JDBC bridges to access IoTDB with the IOTDB-JDBC.*
+1.  **Download Zappy-Sys ODBC-JDBC Bridge**:
+    Enter the 
https://zappysys.com/products/odbc-powerpack/odbc-jdbc-bridge-driver/ website, 
and click "download".
+    
+    
![ZappySys_website.jpg](https://alioss.timecho.com/upload/ZappySys_website.jpg)
+    
+2. **Prepare IoTDB**: Set up IoTDB cluster, and write a row of data 
arbitrarily.
+    ```sql
+    IoTDB > insert into root.ln.wf02.wt02(timestamp,status) values(1,true)
+    ```
+    
+3. **Deploy and Test the Bridge**:
+    1. Open ODBC Data Sources(32/64 bit), depending on the bits of Windows. 
One possible position is `C:\ProgramData\Microsoft\Windows\Start 
Menu\Programs\Administrative Tools`.
+
+       ![ODBC_ADD_EN.jpg](https://alioss.timecho.com/upload/ODBC_ADD_EN.jpg)
+       
+    3. Click on "add" and select ZappySys JDBC Bridge.
+       
+       
![ODBC_CREATE_EN.jpg](https://alioss.timecho.com/upload/ODBC_CREATE_EN.jpg)
+       
+    5. Fill in the following settings:
+
+       | Property            | Content                                         
          | Example                                                             
                                               |
+       
|---------------------|-----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
+       | Connection String   | jdbc:iotdb://\<The IP of IoTDB>:\<The rpc port 
of IoTDB>/ | jdbc:iotdb://127.0.0.1:6667/                                       
                                                |
+       | Driver Class        | org.apache.iotdb.jdbc.IoTDBDriver               
          | org.apache.iotdb.jdbc.IoTDBDriver                                   
                                               |
+       | JDBC driver file(s) | The path of IoTDB JDBC jar-with-dependencies    
          | 
C:\Users\13361\Documents\GitHub\iotdb\iotdb-client\jdbc\target\iotdb-jdbc-1.3.2-SNAPSHOT-jar-with-dependencies.jar
 |
+       | User name           | IoTDB's user name                               
          | root                                                                
                                               |
+       | User password       | IoTDB's password                                
          | root                                                                
                                               |
+       
+       
![ODBC_CONNECTION.png](https://alioss.timecho.com/upload/ODBC_CONNECTION.png)
+       
+    6. Click on "Test Connection" button, and a "Test Connection: SUCCESSFUL" 
should appear.
+   
+       
![ODBC_CONFIG_EN.jpg](https://alioss.timecho.com/upload/ODBC_CONFIG_EN.jpg)
+       
+    7. Click the "Preview" button above, and replace the original query text 
with `select * from root.**`, then click "Preview Data", and the query result 
should correctly.
+   
+       ![ODBC_TEST.jpg](https://alioss.timecho.com/upload/ODBC_TEST.jpg)
+
+## Operate IoTDB's data with ODBC example
+After correct deployment, you can use the example program to operate IoTDB's 
data. 
+
+This program can write data into IoTDB, and query the data we have just 
written. You can directly open the "odbc-example" with JetBrains Rider and run 
it.

Reply via email to