Chinaunix首页 | 论坛 | 博客
  • 博客访问: 799684
  • 博文数量: 127
  • 博客积分: 3662
  • 博客等级: 中校
  • 技术积分: 1371
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-02 12:36
个人简介

Linux&MySQL&PHP&Nginx&Apache&MSSQL&Shell

文章分类

全部博文(127)

文章存档

2016年(1)

2015年(8)

2014年(14)

2013年(26)

2012年(17)

2011年(28)

2010年(33)

分类: SQLServer

2013-11-11 16:32:25


点击(此处)折叠或打开

  1. /* Microsoft SQL Server Integration Services Script Component
  2. * Write scripts using Microsoft Visual C# 2008.
  3. * ScriptMain is the entry point class of the script.*/

  4. using System;
  5. using System.Data;
  6. using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
  7. using Microsoft.SqlServer.Dts.Runtime.Wrapper;
  8. using System.Data.SqlClient;
  9. using MySql.Data.MySqlClient;
  10. using System.Windows.Forms;

  11. [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
  12. public class ScriptMain : UserComponent
  13. {

  14.     private MySqlConnection conn;
  15.     private MySqlDataReader reader;

  16.     public override void AcquireConnections(object Transaction)
  17.     {
  18.         base.AcquireConnections(Transaction);
  19.         this.conn = (MySqlConnection)this.Connections.source.AcquireConnection(null);
  20.     }

  21.     public override void PreExecute()
  22.     {
  23.         base.PreExecute();
  24.         SqlConnection msconn = (SqlConnection)this.Connections.target.AcquireConnection(null);
  25.         SqlCommand mscmd = new SqlCommand("select top 1 id from gt_campaign_la order by id desc", msconn);
  26.         object ohasid = mscmd.ExecuteScalar();
  27.         Int64 hasid;
  28.         if (ohasid == null)
  29.         {
  30.             hasid = 0;
  31.         }
  32.         else
  33.         {
  34.             hasid = Convert.ToInt64(ohasid);
  35.         }
  36.         mscmd.Dispose();
  37.         msconn.Close();
  38.         string sql = "select * from gt_campaign_log where id>@id and create_time<@time and login_userid is not null";
  39.         MySqlCommand mysqlcmd = new MySqlCommand(sql, this.conn);
  40.         MySqlParameter param1 = new MySqlParameter("@id", hasid);
  41.         mysqlcmd.Parameters.Add(param1);
  42.         string a = DateTime.Now.AddHours(-22).ToString("yyyy-MM-dd 00:00:00");
  43.         mysqlcmd.Parameters.Add(new MySqlParameter("@time", a));
  44.         this.reader = mysqlcmd.ExecuteReader();
  45.     }

  46.     public override void PostExecute()
  47.     {
  48.         base.PostExecute();
  49.         this.reader.Close();
  50.     }

  51.     public override void CreateNewOutputRows()
  52.     {
  53.         while (this.reader.Read())
  54.         {
  55.             this.outputBuffer.AddRow();
  56.             this.outputBuffer.id = this.reader.GetInt64("id");
  57.             if (this.reader.IsDBNull(1))
  58.             {
  59.                 this.outputBuffer.utmsource_IsNull = true;
  60.             }
  61.             else
  62.             {
  63.                 this.outputBuffer.utmsource = this.reader.GetString("utm_source");
  64.             }
  65.             if (this.reader.IsDBNull(2))
  66.             {
  67.                 this.outputBuffer.utmmedium_IsNull = true;
  68.             }
  69.             else
  70.             {
  71.                 this.outputBuffer.utmmedium = this.reader.GetString("utm_medium");
  72.             }
  73.             if (this.reader.IsDBNull(3))
  74.             {
  75.                 this.outputBuffer.utmcampaign_IsNull = true;
  76.             }
  77.             else
  78.             {
  79.                 this.outputBuffer.utmcampaign = this.reader.GetString("utm_campaign");
  80.             }
  81.             if (this.reader.IsDBNull(4))
  82.             {
  83.                 this.outputBuffer.cecid_IsNull = true;
  84.             }
  85.             else
  86.             {
  87.                 this.outputBuffer.cecid = this.reader.GetString("ce_cid");
  88.             }
  89.             if (this.reader.IsDBNull(5))
  90.             {
  91.                 this.outputBuffer.pubid_IsNull = true;
  92.             }
  93.             else
  94.             {
  95.                 this.outputBuffer.pubid = this.reader.GetString("pub_id");
  96.             }
  97.             if (this.reader.IsDBNull(6))
  98.             {
  99.                 this.outputBuffer.utmuserinfo_IsNull = true;
  100.             }
  101.             else
  102.             {
  103.                 this.outputBuffer.utmuserinfo = this.reader.GetString("utm_userinfo");
  104.             }
  105.             if (this.reader.IsDBNull(7))
  106.             {
  107.                 this.outputBuffer.locale_IsNull = true;
  108.             }
  109.             else
  110.             {
  111.                 this.outputBuffer.locale = this.reader.GetString("locale");
  112.             }
  113.             if (this.reader.IsDBNull(8))
  114.             {
  115.                 this.outputBuffer.minage_IsNull = true;
  116.             }
  117.             else
  118.             {
  119.                 this.outputBuffer.minage = this.reader.GetString("min_age");
  120.             }
  121.             if (this.reader.IsDBNull(9))
  122.             {
  123.                 this.outputBuffer.maxage_IsNull = true;
  124.             }
  125.             else
  126.             {
  127.                 this.outputBuffer.maxage = this.reader.GetString("max_age");
  128.             }
  129.             if (this.reader.IsDBNull(10))
  130.             {
  131.                 this.outputBuffer.gender_IsNull = true;
  132.             }
  133.             else
  134.             {
  135.                 this.outputBuffer.gender = this.reader.GetString("gender");
  136.             }
  137.             if (this.reader.IsDBNull(11))
  138.             {
  139.                 this.outputBuffer.country_IsNull = true;
  140.             }
  141.             else
  142.             {
  143.                 this.outputBuffer.country = this.reader.GetString("country");
  144.             }

  145.             if (this.reader.IsDBNull(12))
  146.             {
  147.                 this.outputBuffer.ip_IsNull = true;
  148.             }
  149.             else
  150.             {
  151.                 this.outputBuffer.ip = this.reader.GetString("ip");
  152.             }
  153.             if (this.reader.IsDBNull(13))
  154.             {
  155.                 this.outputBuffer.ipcountry_IsNull = true;
  156.             }
  157.             else
  158.             {
  159.                 this.outputBuffer.ipcountry = this.reader.GetString("ip_country");
  160.             }
  161.             if (this.reader.IsDBNull(15))
  162.             {
  163.                 this.outputBuffer.fromgame_IsNull = true;
  164.             }
  165.             else
  166.             {
  167.                 this.outputBuffer.fromgame = this.reader.GetInt32("from_game");
  168.             }
  169.             if (this.reader.IsDBNull(16))
  170.             {
  171.                 this.outputBuffer.logintype_IsNull = true;
  172.             }
  173.             else
  174.             {
  175.                 this.outputBuffer.logintype = this.reader.GetString("login_type");
  176.             }
  177.             if (this.reader.IsDBNull(17))
  178.             {
  179.                 this.outputBuffer.isreg_IsNull = true;
  180.             }
  181.             else
  182.             {
  183.                 this.outputBuffer.isreg = this.reader.GetByte("is_reg");
  184.             }
  185.             if (this.reader.IsDBNull(18))
  186.             {
  187.                 this.outputBuffer.loginuserid_IsNull = true;
  188.             }
  189.             else
  190.             {
  191.                 this.outputBuffer.loginuserid = this.reader.GetInt64("login_userid");
  192.             }
  193.             if (this.reader.IsDBNull(19))
  194.             {
  195.                 this.outputBuffer.loginusername_IsNull = true;
  196.             }
  197.             else
  198.             {
  199.                 this.outputBuffer.loginusername = this.reader.GetString("login_username");
  200.             }
  201.             if (this.reader.IsDBNull(20))
  202.             {
  203.                 this.outputBuffer.logintime_IsNull = true;
  204.             }
  205.             else
  206.             {
  207.                 this.outputBuffer.logintime = this.reader.GetDateTime("login_time");
  208.             }
  209.             if (this.reader.IsDBNull(22))
  210.             {
  211.                 this.outputBuffer.createtime_IsNull = true;
  212.             }
  213.             else
  214.             {
  215.                 this.outputBuffer.createtime = this.reader.GetDateTime("create_time");
  216.             }
  217.             if (this.reader.IsDBNull(23))
  218.             {
  219.                 this.outputBuffer.beblocked_IsNull = true;
  220.             }
  221.             else
  222.             {
  223.                 this.outputBuffer.beblocked = this.reader.GetByte("be_blocked");
  224.             }
  225.             if (this.reader.IsDBNull(24))
  226.             {
  227.                 this.outputBuffer.newuserforgame_IsNull = true;
  228.             }
  229.             else
  230.             {
  231.                 this.outputBuffer.newuserforgame = this.reader.GetByte("new_user_for_game");
  232.             }
  233.             if (this.reader.IsDBNull(25))
  234.             {
  235.                 this.outputBuffer.hasshowcode_IsNull = true;
  236.             }
  237.             else
  238.             {
  239.                 this.outputBuffer.hasshowcode = this.reader.GetByte("has_show_code");
  240.             }
  241.             if (this.reader.IsDBNull(27))
  242.             {
  243.                 this.outputBuffer.firstlogingame_IsNull = true;
  244.             }
  245.             else
  246.             {
  247.                 this.outputBuffer.firstlogingame = this.reader.GetInt32("first_login_game");
  248.             }
  249.             if (this.reader.IsDBNull(28))
  250.             {
  251.                 this.outputBuffer.firstlogingametime_IsNull = true;
  252.             }
  253.             else
  254.             {
  255.                 this.outputBuffer.firstlogingametime = this.reader.GetDateTime("first_login_game_time");
  256.             }
  257.             if (this.reader.IsDBNull(29))
  258.             {
  259.                 this.outputBuffer.hasid_IsNull = true;
  260.             }
  261.             else
  262.             {
  263.                 this.outputBuffer.hasid = this.reader.GetString("has_id");
  264.             }

  265.         }
  266.     }

  267.     public override void ReleaseConnections()
  268.     {
  269.         base.ReleaseConnections();
  270.         this.Connections.source.ReleaseConnection(this.conn);
  271.     }

  272. }

阅读(1124) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~